Order datatable by value in url partial or url parameter
Order datatable by value in url partial or url parameter

Hi,
Is there a way to alter the initial ordering of a table using a partial of a url or a value from a url parameter?
I'm calling data via ajax similar to this example: https://datatables.net/examples/ajax/objects.html
An request might be https://test.local/office
or https://test.local?col=office
In which case I'd like the initial render of the data table to be ordered by office
in descending.
I've read in to the datatables docs and can see how to set the order using an index value, but cannot see anything to indicate the how to use a string
$('#example').dataTable( {
"order": [ 2, 'desc' ]
} );
Is there a way I can use a string to alter the ordering of the data, something similar to this?
$('#example').dataTable( {
"order": [ 'office, 'desc' ]
} );
Thanks
Answers
Hi @mattct ,
This blog post should help, it's demonstrating the same thing.
Cheers,
Colin
Hi @colin
I've had a look and it kind of does, but I can;t see how to order by a string instead of an integer.
The only thing I can think of is to map the strings to values:
And then set the order based on the returned value or a default.
Hi @mattct ,
No, you're right, the order only takes the column index, not the column name, I missed that bit and was pointing to you towards the way to initialise the table based on the URL. If your columns are known and are fixed, you could modify the deepLink code to convert the name to the column index.
Cheers,
Colin