Default Sorting
Default Sorting
When my table is loaded up I load the data in ASC sorting. When I click my table header the first time it tries to sort ASC. being that the data is already sorted that way can I tell datatables that the first click should sort DESC?
This discussion has been closed.
Replies
Interesting one. When DataTables initialises a table of data, one of the first things it does is to sort column 0 'asc' (aaSorting default) - unless it's overridden by the aaSorting initialisation parameter. As such, even if your data is output by PHP+MySQL (or whatever) to be column 0 'asc', DataTables will still try to sort it in this manner (it will be a quick sort though :-) ). Therefore, when you click, the first click should be 'desc'.
To debug this, it would be useful to see what the aaSorting parameter is (oTable.fnSettings().aaSorting) for the various states.
Regards,
Allan
the behaviour i'm after is this:
For "date" columns, i'd like to set the first sort to be DESC (most recent first).
For "string" and "html", the first sort is almost always ASC. (it does this for me already)
Perhaps the control can have baked-in first-sort-directions depending on the sType?
Brent
It's currently not possible to have the default to anything other than 'asc' for any old column (other than the first one), but this is something that I am looking to address in either the next release (1.5.3) or the one following that, depending on how difficult it proves to integrate. There has been discussion about this before:
http://datatables.net/forums/comments.php?DiscussionID=596
http://datatables.net/forums/comments.php?DiscussionID=630
Regards,
Allan
Brent
Outstanding - good to hear it does the trick for you :-)
Thanks for the feedback,
Allan