Sorting classes (sorting_asc/desc) not updating with serverSide and orderData & possible solution
Sorting classes (sorting_asc/desc) not updating with serverSide and orderData & possible solution
Hi all guys, I'm using the DataTables v1.10.16 with the server-side processing and the responsive plugin activated. This is my configuration:
"orderCellsTop": true,
"serverSide": true,
"deferLoading": <NUM_OF_RECORDS>,
"ajax": <URL_TO_MY_PHP>,
"autoWidth": false,
"order": [ [6, "asc"], [2, "asc"], [1, "asc"] ],
"columnDefs": [
{ "targets": 0, ... "searchable": false, "orderable": false ),
{ "targets": 1, ... },
{ "targets": 2, ... "visible": false, "searchable": false, "orderable": false },
{ "targets": 3, ... },
{ "targets": 4, ... },
{ "targets": 5, ... },
{ "targets": 6, ... "orderData": [6, 2, 1] },
{ "targets": 7, ... "searchable": false, "orderable": false }
)
As you can see, I've my table that is initially ordered by the seventh, third and second column (and this works) and I've also setup my seventh column to multi-order the table, using the same columns (seventh, third, second). This is my problem: when table first loads, it is correctly ordered and the sorting_asc/desc classes are well set in the th tags. If i click on the seventh column, an AJAX request is made to my server to re-order the table. I've debugged it and it's correct: it has those fields
order[0][column]: 6
order[0][dir]: desc
order[1][column]: 2
order[1][dir]: desc
order[2][column]: 1
order[2][dir]: desc
requesting the correct order. The answer is also correct (in fact my table gets re-ordered and updated) but if I inspect the columns headers (th tags), only the seventh has the correct class (sorting_asc/desc), while the others have the normal "sorting" class. In addition, if I run this code in my browser console (AFTER the Ajax re-ordering)
$("#<MY_TABLE_ID>").DataTable().order()
this is what I get:
[0: [6, "desc", _idx: 0]]
an array with a single element, that is an array with the only seventh column ordered.
To fix this, I've changed the line 1218 of the un-minified JS file "jquery.dataTables.js" from this
sortedColumns[ val.src ] = val.dir;
to this
sortedColumns[ val.col ] = val.dir;
Is that correct or there were a better way to correct the problem? Thanks.