JQuery 数据表:无法读取未定义的属性“aDataSort" [英] JQuery Datatables : Cannot read property 'aDataSort' of undefined

查看:54
本文介绍了JQuery 数据表:无法读取未定义的属性“aDataSort"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了这个小提琴,它可以很好地满足我的要求:Fiddle

但是,当我在我的应用程序中使用它时,我在浏览器控制台中收到一个错误消息,说无法读取未定义的属性aDataSort"

在我的应用程序中,javascript 读取如下内容:我检查了控制器输出...它运行良好并且也打印在控制台上.

$(document).ready(function() {$.getJSON("three.htm", function(data) {//console.log("loadDataTable >> "+JSON.stringify(data));}).fail(function(jqxhr, textStatus, error ) {var err = textStatus + ', ' + 错误;警报(错误);console.log("请求失败:" + err);}).成功(功能(数据){加载数据表(数据);});函数加载数据表(数据){$("#recentSubscribers").dataTable().fnDestroy();var oTable = $('#recentSubscribers').dataTable({"aaData" : JSON.parse(data.subscribers),处理":真的,bPaginate":假,bFilter":假,bSort":假,bInfo":假,aoColumnDefs":[{"sTitle": "订阅者 ID",目标":[0]}, {"sTitle": "安装位置",目标":[1]}, {"sTitle": "订阅者名称",目标":[2]}, {"aTargets": [0],mRender":函数(数据,类型,完整){return '<a style="text-decoration:none;"href="#" class="abc">'+ 数据 + '</a>';}}],aoColumns":[{"mData": "代码"}, {"mData": "acctNum"}, {mData":名称"}]});}})

解决方案

重要的是你的 THEAD 在 table 中不能为空.因为 dataTable 要求你指定预期数据的列数.根据您的数据,它应该是

<头><tr><th>订户ID</th><th>安装位置</th><th>订户名称</th><th>一些数据</th></tr></thead>

I created this fiddle to and it works well as per my requirements: Fiddle

However, when I use the same in my application I get an error in the browser console saying Cannot read property 'aDataSort' of undefined

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

    }       

})

解决方案

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 数据表:无法读取未定义的属性“aDataSort"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆