Default Sorting

Default Sorting

jcrawfordjcrawford Posts: 172Questions: 0Answers: 0
edited September 2009 in General
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?

Replies

  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi,

    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
  • bjenkinsbjenkins Posts: 5Questions: 0Answers: 0
    Great timing jcrawford, I think I have the same issue. I make use of aaSorting to set my initial sort, but i'm looking for a way to set the first sort direction for another column (a date column).

    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
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi 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
  • bjenkinsbjenkins Posts: 5Questions: 0Answers: 0
    Allan i just tried the new default sort order in v1.5.3 and it works like a charm! thanks for the quick turnaround!
    Brent
  • allanallan Posts: 63,498Questions: 1Answers: 10,470 Site admin
    Hi Brent,

    Outstanding - good to hear it does the trick for you :-)

    Thanks for the feedback,
    Allan
This discussion has been closed.