我收到错误说
中运行以下脚本时SCRIPT5007:无法获取未定义或null的属性'aDataSort' 参考 jquery.dataTables.min.js(65,437)
$(document).ready(function() {
var arr = [];
for (var i = 0; i < 5; i++) {
var item = {};
item["c1"] = "a" + i;
item["c2"] = "b" + i;
arr.push(item);
};
var dataSet = JSON.stringify(arr);
console.log(dataSet);
$('#example').DataTable({
"data": dataSet
});
});
答案 0 :(得分:0)
您可能会收到此错误,因为您尝试将数据表实例化两次 - 在我的情况下,我有一个genericDataTable
类的数据表和someDataTable
的id(大致)以下JS代码:
$(document).ready(function () {
$('.genericDataTable').DataTable()
...Lots of other JS Code...
$('#someDataTable).DataTable({
"columns": [
{
"title": "Name",
"data": "Name"
},
{
"title": "Street",
"data": "Street",
},
{
"title": "City",
"data": "City"
},
{
"title": "State",
"data": "State"
},
{
"title": "Actions",
"data": "Id"
}
]
});
});