1
votes

Hello i have created a table using the jquery datatable framework to display data.

automatically my datables are sorted into a form in which i do not want

so i did some research on how to disable sorting and then i get sorting disabled.

the problem now is when i disabled sorting i get a funny error :

"DataTables warning: table id=datatable - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3"

so i do another round of research on why i am having this problem.

the problem is i am calling the dataTable() function twice on my page

so the solution should be to only call it once.

the second problem i have is i dont know where the first function has been called.

Reason : i am making use of a template and it does not state explicitly where this is defined.

how can i get rid of this error? is there any method.

please see my implementation for disabling sorting below which works for sorting but triggers that error

   $(document).ready(function() {
      $('#datatable').dataTable({
          "bSort": false,
          "bDestroy": true
       });
    });

what i am trying to achieve is display my datatable without sorting

Thanks

1

1 Answers

2
votes

You need to destroy the existing DataTable before re-initializing it:

$(document).ready( function() {
  if ( $.fn.DataTable.isDataTable( '#datatable' ) ) {
    $( '#datatable' ).DataTable().destroy();
  }
  $( '#datatable' ).dataTable( {
    "bSort": false,
    "bDestroy": true
  } );
} );