2013-05-14 35 views
0

好的,這是一個讓我瘋狂的問題。已添加數據(大小未定義)與已知列數(9)不匹配

我試圖創建一個jQuery DataTable,並不斷收到錯誤:
數據表警告(表ID =「屬性」):新增數據(大小未定義)不匹配已知數列(9)

我有一個設置了9列(即9個<th>塊在html)的表

的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),但無法找到任何指出問題的東西...

+0

只是爲了清楚起見,我使用jQuery 1.7.6 – SnagQueensHubby

+0

ShusterPropertyID不等於ShusterPropertyId - 你有兩個人一樣,以及您的JSON數據不匹配aaColumns。我相信aaDataProp和aaColumns必須與正確的案例相匹配。 ShusterCustomerID和BEPropertyID是其他的。 – wilsjd

+0

請分享表格html,並回應上述評論 –

回答

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」],[ 「2012年12月20日」, 「1」],[「2012-12- 17「,」1「],[」2012-12-21「,」1「],[」2012-12-12「,」1「]]}

因此,要獲得這個合成數據,請執行以下操作: $ rResult = $ this-> db-> query($ sQuery); $ rResult = $ rResult-> result_array();

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


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





    $row[] = $val; 
} 

     $output['aaData'][] = $row; 
    } 
echo json_encode($output); 
相關問題