我试图通过初始化表来使用jquery表,如
$("#someTable").DataTable();
这给了我一个对象引用,它包含成员方法,如列,列等。这里someTable
是一个普通的静态表,在thead中指定了列,并且很少有静态行。
我正在尝试初始化其他使用服务器端分页的表,并且未在tag中指定列但在datatable 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"},
];
这给出了不包含列和列属性的响应。我需要访问这些属性。有人有解决方案吗?
答案 0 :(得分:1)
<强>原因强>
您的代码存在一些问题:
}
aoColumns
变量应该在之前定义在DataTables初始化期间使用它。<强>解强>
正确的代码如下所示
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
});