Controlling default direction of multi column order
Controlling default direction of multi column order
I've been chasing this problem around for a while now - I'm almost certain there will be a simple solution but I can't see it. Any help would be greatly appreciated!
I have a table which contains a name column and a date column (among others).
When a user sorts by the name column (in either direction) I would like to order the date column in DESC order. This is what I have so far:
columns: [
{data: 'compliance', name: 'compliance', searchable: false},
{data: 'resident.last_name', name: 'resident.last_name'},
{data: 'accident_date', name: 'accident_date', searchable: false},
{data: 'status', name: 'status'},
],
columnDefs: [
{ "orderData": [ 1, 2 ], "targets": 1 },
],
Currently, if a user sorts the name column in ascending order it sorts the date in ascending order too. Similarly, if they sort name in descending order the date gets sorted in descending order.
I would like the date column to be shown in descending order even when the name column is set to ascending.
If possible, I would still like to maintain the default behaviour whereby a user can shift-click columns to set their own preference for multi-column sorting.
Thanks.
This question has an accepted answers - jump to answer
Answers
Unfortunately there is no way to do this I'm afraid. The additional columns for
columns.orderData
can currently only match the ordering direction of the host column.That is a limitation I'm aware of and want to address in future.
Sorry I don't have a better answer atm.
Allan
No problem Allan.
Thanks for all your hard work on DataTables.