好吧,这个让我发疯了。
我正在尝试创建一个 jQuery 数据表并不断收到错误消息:
DataTables 警告(表 id = 'properties'):添加的数据(大小未定义)与已知的列数不匹配 (9)
我有一个设置了 9 列的表(即<th>
html 中的 9 个块)
Javascript 看起来还不错(尽管如果有人能肯定地验证它会有所帮助):
$tableProperties = $('#properties').dataTable({
sDom: '<"dataTables_header"<"dataTables_toolbar">rl>t<"dataTables_footer"ip>',
oLanguage: { sLengthMenu: "Show _MENU_ lines", sInfo: "Showing _START_ to _END_ of _TOTAL_ lines" },
iDisplayLength: <%: ShusterConnect.ConfigurationSettings.MgtPropertiesPerPage %>,
aLengthMenu: [[10, 20, 50, -1], [10, 20, 50, "All"]],
bPaginate: true,
sPaginationType: "listbox",
bLengthChange: true,
bFilter: false,
bInfo: true,
bAutoWidth: true,
bProcessing: true,
bServerSide: true,
sAjaxSource: "/property/QueryAllProperties",
aaSorting: [[ 5, "asc" ]], // default sorting column is Management Company
fnServerData: function (sSource, aoData, fnCallback) {
$.post(sSource, aoData, fnCallback);
},
fnRowCallback: function (tr, record, iDisplayIndex, iDisplayIndexFull) {
$('td:eq(7)', tr).html(renderActionTemplate(record[7], $('td:eq(4)', tr).text()));
$('td:eq(7)', tr).css("white-space", "nowrap");
if ($('td:eq(4)', tr).text() != "Yes")
$(tr).css("background-color", "#c0c0c0");
return tr;
},
aoColumns: [
{ "mDataProp": "ShusterPropertyID" },
{ "mDataProp": "ShusterCustomerID" },
{ "mDataProp": "BEPropertyID" },
{ "mDataProp": "BEUserName" },
{ "mDataProp": "IsManagementCompany" },
{ "mDataProp": "ManagementCompany" },
{ "mDataProp": "MappingFileType" },
{ "mDataProp": "Action", "bSortable": false}, // action
{ "mDataProp": "ParentId" } //Parent Id
],
});
});
我的 JSON 返回一个 aaData 集,每条记录有 9 个值:
{"sEcho":"1","iTotalRecords":147,"iTotalDisplayRecords":147,"aaData":[{"ShusterCustomerId":"1057","ShusterPropertyId":"DEV","BEPropertyId":"4368058011","BEUserName":"Devon Oaks","IsManagementCompany":"","ManagementCompany":"Eliza Jennings Senior Care Network","MappingFileType":"Default","Action":"57","ParentId":""},{"ShusterCustomerId":"1058","ShusterPropertyId":"ELIZA","BEPropertyId":"4368056561","BEUserName":"Eliza Jennings Home","IsManagementCompany":"","ManagementCompany":"Eliza Jennings Senior Care Network","MappingFileType":"Default","Action":"58","ParentId":""}, ... {"ShusterCustomerId":"1168","ShusterPropertyId":"WESC","BEPropertyId":"3008297838","BEUserName":"Wesley Court Methodist Retirement Community","IsManagementCompany":"","ManagementCompany":"Sears Methodist Retirement System","MappingFileType":"PathLinks","Action":"243","ParentId":"232"}]}
所以...到底发生了什么?我错过了什么重要的事情吗?任何建议将不胜感激。
PS我确实花了一个小时搜索互联网(和StackOverflow),但找不到任何指向问题的东西......