0
votes

I'm trying to sort a table by a particular column with DataTables, but I receive this warning:

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

I put these scripts but maybe I'm doing something wrong:

jQuery('.sp-template-league-table table').DataTable({ paging: false, searching: false, info: false, retrieve: true });

jQuery('.sp-template-league-table table').DataTable().column('.data-tot').order('asc').draw();

You can see the table in this page: http://www.quartuleague.com/goldcup-2015-girone-gold/

under the "Fair Play" Tab, i want to sort table by "TOT"

1
As far as I can see the table actually holds the unique class .sp-league-table so jQuery('.sp-league-table table').DataTable().column('.data-tot').order('asc').draw(); - davidkonrad
Possible duplicate of Sort table by class in TH - Gyrocode.com

1 Answers

0
votes

If you want to sort the data by default you can also pass along additional parameters on the initialization instead of using .draw():

Example: Ascending sorting of the 4th column (indices start at 0)

$('#example_table').DataTable( {
    "order": [[ 3, "asc" ]]
} );

In your case you need to add the column number of your data-tot column (8 or -1) like so:

jQuery('.sp-template-league-table table').DataTable({ 
order: [[ 8, "asc" ]],
paging: false, 
searching: false, 
info: false, 
retrieve: true 
});