How to "no sort" by default?

How to "no sort" by default?

adamadam Posts: 11Questions: 0Answers: 0
edited February 2010 in General
Hi guys

I want to keep using the sort functionality provided by datatables but, by default I want to turn this off.

I'm using Sphinx (www.sphinxsearch.com/) to return my SQL matches. Sphinx orders these matches by relevance based on my keywords. So I'd like to keep that as the default sort order.

Then, if a user would prefer to sort by column X, then datatables can kick in and work it's magic.

Any ideas how I set this up?

I've looked at aaSorting, but I can't set this to false http://datatables.net/usage/options

Replies

  • adamadam Posts: 11Questions: 0Answers: 0
    So in other words... I want datatables to sort when users click column headings (bSort=true)
    But by default I don't want datatables to sort anything (can I use aaSorting=false..... or similar?)

    Any help is appreciated :)
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Sorting completely off: bSort ( http://datatables.net/usage/features#bSort )

    Sorting off initially, but user can still click to sort on columns: aaSorting: [] (i.e. empty array).

    Allan
  • adamadam Posts: 11Questions: 0Answers: 0
    Awesome. Thanks Allan!
  • jnthnlstrjnthnlstr Posts: 27Questions: 0Answers: 0
    Thanks for [] solution - it would be helpful to have this in the docs for aaSorting.
  • allanallan Posts: 63,535Questions: 1Answers: 10,475 Site admin
    Added it to the code example in the docs :-)

    Allan
  • nirglenirgle Posts: 3Questions: 0Answers: 0
    Excellent tip, thanks. I display my "Date Added" columns using the date portion only, but my data store returns them in proper order taking into consideration the times within the day as well, and it's nice to sort them by the order they were actually inserted into the table on that day. Thanks again.
  • edgreenbergedgreenberg Posts: 1Questions: 0Answers: 0
    Thanks for the answer. I need an initial sort order to match the record order provided, while still allowing user requested sorts, post display. Any idea how that can be done?
  • beginner_beginner_ Posts: 55Questions: 2Answers: 0
    edited September 2011
    I think there is a bug in 1.8.1 with FireFox 3.6.16 (and maybe other versions). I can't get this to work. It works fine in IE 8.

    In FireFox sorting is done on the first column even with aaSorting: []. I cleared the cache and forced a refresh with ctrl+F5. Also restart firefox and windows. Nothing helped I then looked at the firefox cache and the JSON object was actaully cached too and in the correct sort i want (sql order by).
    The page source in FireFox also shows aaSorting: [].

    Because of all this i think it's a bug and not a cache issue. Any ideas?

    EDIT:
    This was some kind of weird caching issue. I don't get it since I cleared cache and restarted PC. But it just worked fine after the weekend...
  • kanyungukanyungu Posts: 3Questions: 1Answers: 0
    Good stuff, Thanks for the [] soln
  • GrahamGraham Posts: 1Questions: 0Answers: 0
    Had the same wierd caching problem that beginner_ mentioned. Didn't have to wait a weekend though, just cleared the cookies. I had tried clearing the cache already, so possibly both are needed.

    I'm using firefox version 8.0.1
This discussion has been closed.