0

I am fetching records from Database and displaying in table. And for search i used datatables. but i want to disable default sorting of datatables. So i tried to disable sorting by using following code

    $('#offer_table').dataTable({
         "aaSorting": []
  });

its working perfectly , but the issue is , its shows some alert

you cannot reinitialize datatable

How to fix this problem ? May be this question is silly but sorry i tried in google to fix this issue but i cant able to fix. Thank you.

1
  • Please don't include screenshots of code or error messages. It makes it hard for people to search for it later. Commented Jun 19, 2015 at 18:39

2 Answers 2

2

This could happen due to some reasons, but usually because you tried to initialize twice or set the properties after initialize.

Check this link for more info about this issue.

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

Comments

2

Yes, just to add to douglasf89's answer, you are probably trying to initialize the Datatable twice. If you must do this, it is first necessary to call

yourTable.destroy();

between intitializations.

Thus, the code below is valid:

function createTable() {
  yourTable = $('#offer_table').dataTable({
     "aaSorting": []
  });
}
createTable();
yourTable.destroy();
createTable();

Still, this link answers your question more thoroughly.

While your problem may not be caused by aaSorting, there are alternate syntaxes to accomplish this. Legacy Datatables doc - (legacy.datatables.net/ref), you may substitute aaSorting with

$('#example').dataTable( {
  "bSort": false
} );

to disable sorting on a specific column, use

$('#example').dataTable( {
    "aoColumnDefs": [
      { "bSortable": false, "aTargets": [ 0 ] }
] } );

to change the default column to sort by, use

var oTable = $('#example').dataTable();

// Sort immediately with columns 0 and 1
oTable.fnSort( [ [0,'asc'], [1,'asc'] ] );

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.