添加的数据(未定义大小)与已知列数不匹配(9)

时间:2013-05-14 19:51:22

标签: jquery json datatables

好的,这个让我疯了。

我正在尝试创建一个jQuery Datatable并继续收到错误:
DataTables警告(表id ='properties'):添加的数据(未定义大小)与已知列数不匹配(9)

我设置了一个包含9列的表格(即html中的9个<th>块)

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

那么......到底是怎么回事?我错过了一些重要的事吗?任何建议都将不胜感激。

P.S。我花了一个小时搜索interwebs(和StackOverflow),但是找不到任何可以指出问题的东西......

1 个答案:

答案 0 :(得分:1)

json数据格式应如下所示: { “sEcho”:17, “iTotalRecords”:35, “iTotalDisplayRecords”:35, “aaData”:[[ “2012年12月1日”, “1”],[ “2012年12月27日”, “1” ],[ “2012-12-26”, “1”],[ “2012年12月27日”, “1”],[ “2012年12月19日”, “1”],[“2012-12- 27" , “1”],[ “2012年12月27日”, “1”],[ “2012年12月27日”, “1”],[ “2012年12月27日”, “1”], [ “2012年12月27日”, “1”],[ “2012年12月27日”, “1”],[ “2012年12月21日”, “1”],[ “2012年12月27日” , “1”],[ “2012-12-25”, “1”],[ “2012-12-26”, “1”],[ “2012-01-03”, “1”],[” 2012年11月23" 日, “1”],[ “2012年12月2日”, “1”],[ “2012年11月22日”, “1”],[ “2012年12月24日”,” 1 “],[” 2012年11月14" 日, “1”],[ “2012年11月22日”, “1”],[ “2012年11月23日”, “1”],[“2012- 11-22" , “1”],[ “2012年11月22日”, “1”],[ “2012年11月26日”, “1”],[ “二零一二年十二月二十日”, “1” ],[ “二〇一二年十二月一十七日”, “1”],[ “2012年12月21日”, “1”],[ “2012年12月12日”, “1”]]}

为了获得这种数据格式,请执行以下操作:     $ rR​​esult = $ this-&gt; db-&gt; query($ sQuery);      $ rR​​esult = $ rResult-&gt; result_array();

foreach ($rResult as $aRow) {
     $row = array();


 foreach ( $aRow as $key => $val ) {





  $row[] = $val;
}

      $output['aaData'][] = $row;
    }
echo json_encode( $output );