How can I change the column which is being ordered?
How can I change the column which is being ordered?
lokko
Posts: 3Questions: 1Answers: 0
I have a table with three columns, which is currently being sorted ascending in the first column. However, I would instead like to be sorting descending by the third column (index 2) when the webpage loads. I've had a look around but none of the solutions have worked for me, most notably using:
new DataTable('#example', {
order: [[2, 'desc']]
});
Any help would be apprecaited.
This question has accepted answers - jump to:
Answers
Your code snippet works in this tets case:
https://live.datatables.net/yonotuki/1/edit
Please provide a link to your page or a test case replicating the issue so we can help debug.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Some of the things I can think that could be a problem:
Kevin
Thanks for your reply @kthorngren ! I know this is very inconvenient but I unfortunately cannot share the code. The sort of thing I was looking for was some line of code which I could change in the jquery.dataTables.js file to make this happen (downloaded from the project builder).
We can't really give you that code or line of code, since the example that Kevin gave you shows it working as expected. That suggests that the is a problem unique to the page you have which we would need to be able to see to be able to debug.
Most likely it is a configuration issue, or perhaps you have
serverSide
enabled and the server-side script doesn't correctly implement ordering?Can you use the debugger to give me a trace please - click the Upload button and then let me know what the debug code is. That might give me enough of a clue to see what is going wrong.
Allan
Apologies, I've now managed to get it working thanks to the help I've received! Thanks again!
Have you tried this?
It is not expected or recommended to modify the
jquery.Datatables.js
file to apply configurations.Kevin