首页 > 代码库 > DataTable获取列数据

DataTable获取列数据

 1  get_spec_col_data: function(custom_options){ 2             var result = []; 3             var options = { 4                 table_id: ‘‘, 5                 table_data_key: ‘grid‘, 6                 column_index: 0, 7                 selected: false, 8                 select_type: ‘checkbox‘ 9             }10             jQuery.extend(options, custom_options);11             options.table_id = ‘#‘ + options.table_id;12             var multi_data = http://www.mamicode.com/false;13             if (typeof (options.column_index) == undefined){14                 return result;15             } else if ( (options.column_index.constructor + ‘‘).match(/function Array\(\)/) != null ) {16                 multi_data = http://www.mamicode.com/true;17             }18             var data_arr = jQuery.data(jQuery(options.table_id)[0], options.table_data_key).fnGetData();19             if (options.select_type == ‘radio‘) {20                 var nodes_arr = jQuery(‘td:first input:radio‘,21                     jQuery.data(jQuery(options.table_id)[0], options.table_data_key).fnGetNodes());22             } else if (options.select_type == ‘checkbox‘) {23                 var nodes_arr = jQuery(‘td:first input:checkbox‘,24                     jQuery.data(jQuery(options.table_id)[0], options.table_data_key).fnGetNodes());25             } else {26                 return result;27             }28 29             for (var i = 0; i < data_arr.length; i++) {30                 if (!options.selected || (nodes_arr[i] && nodes_arr[i].checked)) {31                     if (multi_data){32                         var tmp = [];33                         for (var j = 0; j < options.column_index.length; j++){34                             tmp.push(data_arr[i][options.column_index[j]]);35                         }36                         result.push(tmp);37                     }else{38                         result.push(data_arr[i][options.column_index]);                        39                     }40                 }41             }42             43             // Set hidden checked record.44             if (options.selected) {45                 // If the temporary data is existed (i.e. this method is called 46                 // from fnDrawcallback), the temporary data, which is included 47                 // checked hidden data and displayed record, should be used.48                 var $table = $(options.table_id),49                     target_data =http://www.mamicode.com/ esf_fw.table.get_tmp_raw_check_data_list($table);50                 if (!target_data) {51                     target_data = http://www.mamicode.com/52                         esf_fw.table.get_hidden_raw_check_data($(options.table_id));53                 }54                 55                 if (multi_data) {56                     $.each(target_data, function(key, value) {57                         var tmp = [];58                         $.each(options.column_index, function(j, index){59                             tmp.push(value[index]);60                         });61                         result.push(tmp);62                     });63                 } else {64                     $.each(target_data, function(key, value) {65                         result.push(value[options.column_index]);66                     });67                 }68             69             }70             return result;71         },

 

DataTable获取列数据