20

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 }

8
  • where in your code you are trying to read assorting..paste that code.. Commented Nov 10, 2012 at 6:45
  • no I don't want asorting. I haven't done any coding for that. By default this error is comming Commented Nov 10, 2012 at 6:46
  • its not what u want..its where u've used it?? so that we can see whats wrong.. Commented Nov 10, 2012 at 6:48
  • I am not at all using that property. Commented Nov 10, 2012 at 6:49
  • What other scripts are you including aside from jquery? Commented Nov 10, 2012 at 6:51

5 Answers 5

37

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>

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

1

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

Comments

0

Thanks,

Table should have & section.

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.