Default sort order when using DataTables?
Default sort order when using DataTables?

How can I specify a default sort order of my recordset when using DataTables? Right now, the default sort order of the query is being ignored in my output.
Thank you.
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use the
order
option to set the default order. If this doesn't help then please post the Datatables init code showing the default order you want.Kevin
I found this info, but when I use this code in my page, I get an error.
DataTables warning: table id=example - Cannot reinitialise DataTable. For more information about this error, please see http://datatables.net/tn/3
I can't figure out why it's not working.
Did you follow the troubleshooting steps in the link ( http://datatables.net/tn/3 )?
Kevin
Yes, but I didn't see anything to do with a sort error. I just want it to sort by my first column in descending order as a default, so I tried this, and got the error.
The error means that Datatables has been initialized elsewhere in your code, ie,
$('#example').DataTable( ...} );
. If this is the case move the"order": [[ 1, "desc" ]],
into that initialization. If you still need help then we will need to see the problem by looking at a link to your page or a test case replicating the issue.https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Kevin, thank you so much! Now I understand. I am using an included file in my file, and calling it there as well (I forgot about that!). It's working as expected now.
Thank you!!!