Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery datatable integration error?

Tags:

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 }

like image 670
niran Avatar asked Nov 10 '12 06:11

niran


2 Answers

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>

like image 101
Bumptious Q Bangwhistle Avatar answered Sep 17 '22 20:09

Bumptious Q Bangwhistle


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.

like image 26
MoFlo Avatar answered Sep 19 '22 20:09

MoFlo