我正在尝试通过初始化表来使用jQuery表
$("#someTable").DataTable();
这给了我对象引用,其中包含成员方法,例如column,columns等。这里的
someTable
是一个普通的静态表,具有在thead中指定的列和少量静态行。我正在尝试初始化其他使用服务器端分页的表,这些列未在标记中指定,而是在数据表aoColumns中指定。喜欢
listDataTable= $("#ListDataPane_data").DataTable({
"iDisplayLength":100,
"bFilter": true,
"bServerSide": true,
"sServerMethod": "POST",
"sAjaxSource": PaginationUrl,
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": false,
"bDestroy": true,
"bStateSave": true,
"sScrollY":"300",
"aaSorting":orderSort,
"aoColumns": aoColumns,
"bScrollInfinite": true,
"sScrollY": "300px",
"sScrollX": "963px",
"bAutoWidth": false,
},
});
var aoColumns = [
{ "sTitle": "Action","sWidth":"30px","sName": "Action","sClass":"column_action","bSortable":false},
{ "sTitle": "","sWidth":"30px", "bSortable":false },
{ "sTitle": " ","sWidth":"20px" , "bSortable":false},
{ "sTitle": "Mode","sWidth":"100px" ,"sName": "orderType","bSearchable": true,"sClass":"column_pm","bSortable":true},
{ "sTitle": "Provider","sWidth":"80px" ,"sName": "providerName","sClass":"column_action"},
{ "sTitle": "Id","sWidth":"80px","sName":"id","bSortable":true,"sClass":"column_orderid"},
{ "sTitle": "Status" ,"sWidth":"100px","sName": "Status","sClass":"column_action"},
{ "sTitle": "Validated By", "bSearchable": true, "bVisible": false ,"sWidth":"100px","sName": "validatedBy" , "bSortable":true,"sClass":"column_validated"},
];
这给出的响应不包含column和columns属性。我需要访问这些属性。有人有什么解决办法吗?
最佳答案
原因
您的代码存在一些问题:
不必要的结束括号}
在数据表初始化期间使用它之前,应先定义aoColumns
变量。
尾随逗号
解
正确的代码如下所示
var aoColumns = [
{ "sTitle": "Action","sWidth":"30px","sName": "Action","sClass":"column_action","bSortable":false},
{ "sTitle": "","sWidth":"30px", "bSortable":false },
{ "sTitle": " ","sWidth":"20px" , "bSortable":false},
{ "sTitle": "Mode","sWidth":"100px" ,"sName": "orderType","bSearchable": true,"sClass":"column_pm","bSortable":true},
{ "sTitle": "Provider","sWidth":"80px" ,"sName": "providerName","sClass":"column_action"},
{ "sTitle": "Id","sWidth":"80px","sName":"id","bSortable":true,"sClass":"column_orderid"},
{ "sTitle": "Status" ,"sWidth":"100px","sName": "Status","sClass":"column_action"},
{ "sTitle": "Validated By", "bSearchable": true, "bVisible": false ,"sWidth":"100px","sName": "validatedBy" , "bSortable":true,"sClass":"column_validated"}
];
var listDataTable = $("#ListDataPane_data").DataTable({
"iDisplayLength": 100,
"bFilter": true,
"bServerSide": true,
"sServerMethod": "POST",
"sAjaxSource": PaginationUrl,
"bProcessing": true,
"sPaginationType": "full_numbers",
"bJQueryUI": false,
"bDestroy": true,
"bStateSave": true,
"sScrollY": "300",
"aaSorting": orderSort,
"aoColumns": aoColumns,
"bScrollInfinite": true,
"sScrollY": "300px",
"sScrollX": "963px",
"bAutoWidth": false
});