JQuery Datatables:无法读取未定义的属性'aDataSort' [英] JQuery Datatables : Cannot read property 'aDataSort' of undefined
问题描述
我创建了这个小提琴,根据我的要求,它的效果很好:小提琴
I created this fiddle to and it works well as per my requirements: Fiddle
但是,当我在应用程序中使用相同的时候,我在浏览器控制台中出现错误,说无法读取未定义的属性aDataSort
However, when I use the same in my application I get an error in the browser console saying Cannot read property 'aDataSort' of undefined
在我的应用程序中,JavaScript读取如下所示:我已经检查了控制器输出...它工作得很好,也被打印在控制台上。
In my application, the javascript reads something like as below: I have checked the controller output...it works well and is printed on the console too.
$(document).ready(function() {
$.getJSON("three.htm", function(data) {
// console.log("loadDataTable >> "+JSON.stringify(data));
})
.fail(function( jqxhr, textStatus, error ) {
var err = textStatus + ', ' + error;
alert(err);
console.log( "Request Failed: " + err);
})
.success(function(data){
loadDataTable(data);
});
function loadDataTable(data){
$("#recentSubscribers").dataTable().fnDestroy();
var oTable = $('#recentSubscribers').dataTable({
"aaData" : JSON.parse(data.subscribers),
"processing": true,
"bPaginate": false,
"bFilter": false,
"bSort": false,
"bInfo": false,
"aoColumnDefs": [{
"sTitle": "Subscriber ID",
"aTargets": [0]
}, {
"sTitle": "Install Location",
"aTargets": [1]
}, {
"sTitle": "Subscriber Name",
"aTargets": [2]
}, {
"aTargets": [0],
"mRender": function (data, type, full) {
return '<a style="text-decoration:none;" href="#" class="abc">' + data + '</a>';
}
}],
"aoColumns": [{
"mData": "code"
}, {
"mData": "acctNum"
}, {
"mData": "name"
}]
});
}
})
推荐答案
重要的是,您的THEAD在表中不为空。由于dataTable要求您指定预期数据的列数。
根据你的数据应该是
It's important that your THEAD not be empty in table.As dataTable requires you to specify the number of columns of the expected data . As per your data it should be
<table id="datatable">
<thead>
<tr>
<th>Subscriber ID</th>
<th>Install Location</th>
<th>Subscriber Name</th>
<th>some data</th>
</tr>
</thead>
</table>
这篇关于JQuery Datatables:无法读取未定义的属性'aDataSort'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!