我正在研究数据表,我的数据表没有显示表中的最后一列。例如,如果我有30列,则数据表不显示第30列。它只显示第29列,尽管我通过ajax响应收到了完整的数据。
上图仅显示3列。但是我们有4列。请看下面这张图片......
见下面的所有代码......
var table = $('#csv_as_dataTable').DataTable({
"colReorder": {
fixedColumnsLeft: 1,
fixedColumnsRight: 1,
},
"pagingType": "full_numbers",
"scrollX": false,
"colReorder": true,
"iDisplayLength": 100,
"aLengthMenu": [[100, 200, 500, 1000], [100, 200, 500, 1000]],
"initComplete": function(settings, json) {
$('#csv_as_dataTable').wrap("<div id='db_scroll'></div>");
},
//"responsive": true,
"bProcessing": true,
"oLanguage": {
"sProcessing": "<div class='datatableNewProcessor'>Processing..</div>"
},
"aaSorting": [],
"columns": JSON.parse(headersData),
"bFilter": false,
"bServerSide": true,
"columnDefs": [{
"targets": -1,
"visible": false,
}],
"sAjaxSource": "/es_scripts/data_table_server.php",
"fnServerData": function (sSource, aoData, fnCallback) {
aoData.push({"name": "indexName", "value": indexName});
aoData.push({"name": "indexType", "value": indexType});
//getting the values form fields
var filersCount = $('input[name="filter_count"]').val();
var filterJson = "";
for (i = 1; i <= filersCount; i++) {
if ($('#filter' + i).length == 0) {
continue;
}
if ($('#fil_val' + i).val() == "") {
continue;
}
var colname = $('#cols_list' + i).val();
var operator = $('#op_list' + i).val();
var required_val = $('#fil_val' + i).val();
if (colname == '' || operator == '') {
alert('Column name & operators are required to apply filter');
return false;
}
filterJson += '{"colname":"' + colname.split(' ').join('_') + '", "operator":"' + operator + '", "required_val":"' + required_val + '"},';
}
filterJson = filterJson.replace(/,\s*$/, "");
filterJson = "[" + filterJson + "]";
aoData.push({"name": "filterJson", "value": filterJson});
console.log("************filterjson**************");
console.log(filterJson);
console.log("***************************");
//@ajax call to server
$.ajax({
"dataType": 'json',
"type": "GET",
"url": sSource,
"data": aoData,
"success": function (json) {
//var json = '{"iDisplaying": 3,"iTotalDisplayRecords": 3,"iTotalRecords": 3,"aaData": [["Nixon","Architect","5421"],["Nixon1","Architect1","54211"],["Nixon2","Architect","5421"]]}';
console.log("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
//console.log(JSON.parse(json));
console.log(json);
console.log("&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&");
//fnCallback(JSON.parse(json));
fnCallback(json);
},
"timeout": 30000, // Optional if you want to handle timeouts (which you should)
//"error": handleAjaxError // this sets up jQuery to give me errors.
});
/////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
},
});
答案 0 :(得分:3)
我相信你的问题就在这个地方,你正在隐藏最后一栏。
"columnDefs": [{
"targets": -1,
"visible": false,
}],
正如文件所说:
例如目标:[-1,-2]将定位最后一个和最后一个 表中的列。