Jquery datatable integration error?

烈酒焚心 提交于 2019-12-21 03:18:06

问题


I am integrating jquery datatable to my project. When call is made to service, some how following error is error thrown

cannot read property 'assorting' of undefined

Here is the code

Timeline

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script  src="js/jquery.dataTables.js"></script>

<body>

<script>

$(document).ready( function() {
  $('#example').dataTable( {
    "bProcessing": true,
    "bServerSide": true,
    "sAjaxSource": "URL",
    "fnServerData": function ( sSource, aoData, fnCallback, oSettings ) {
    console.log(aoData);
      oSettings.jqXHR = $.ajax( {
        "dataType": 'json',
        "type": "POST",
        "url": sSource,
        "data": aoData,
        "success": fnCallback
      } );
    }
  } );
} );

</script>

<div id="dvContent">
 <table cellpadding="0" cellspacing="0" border="0"  id="example">

 </table>
</div>

</body>

Here is the Sample out put of the server

{"some":"yyy", "open":null, "program":1, "more":"must", "comment":000 }


回答1:


Your table needs a THEAD section and a TBODY section:

<table cellpadding="0" cellspacing="0" border="0"  id="example">
   <thead><tr><th>First Column</th><th>Second Column etc.</th></tr></thead>
   <tbody>
   </tbody>
</table>

Note: it's also important that your THEAD not be empty as dataTable requires you to specify the number of columns of the expected data as specified by <tr><th></th></tr>




回答2:


In addition to the point by @bumptious above, it's important to note that the THEAD section cannot be blank; dataTables requires the <tr><th>column1</th></tr> content as placeholder within the table.




回答3:


This error can also occur when you use "order" clause and refer to non-existing field/column.




回答4:


Thanks,

Table should have & section.




回答5:


Make sure your table's number of data columns td is equal to header columns th.



来源:https://stackoverflow.com/questions/13319979/jquery-datatable-integration-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!