JQuery Datatables:无法读取未定义的属性'aDataSort'

我创build了这个小提琴,并按照我的要求,它工作得很好: 小提琴

但是,当我在我的应用程序中使用相同的时候,我在浏览器控制台中得到一个错误,说不能读取未定义的属性'aDataSort'

在我的应用程序中,JavaScript读取如下所示:我已检查控制器输出…它工作正常,并在控制台上打印。

$(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" }] }); } }) 

数据表需要您指定预期数据的列数,这一点非常重要。 根据你的数据应该是

 <table id="datatable"> <thead> <tr> <th>Subscriber ID</th> <th>Install Location</th> <th>Subscriber Name</th> <th>some data</th> </tr> </thead> </table> 

也有这个问题,这个数组超出范围:

 order: [1, 'asc'], 

我也有这个问题,下面的改变解决了我的问题。

 $(document).ready(function() { $('.datatable').dataTable( { bSort: false, aoColumns: [ { sWidth: "45%" }, { sWidth: "45%" }, { sWidth: "10%", bSearchable: false, bSortable: false } ], "scrollY": "200px", "scrollCollapse": true, "info": true, "paging": true } ); } ); 

aoColumns数组描述了每列的宽度及其sortable属性。