Un-ordering

Un-ordering

johnblythejohnblythe Posts: 92Questions: 21Answers: 2

hey allan,

is there a way to un do any ordering? i have a DT using server side processing that orders by default on a descending Total Cost column. when the user searches, however, i want their results to be ordered by relevancy—something that I have set up in the backend to happen automatically—not the cost lest their most relevant result be somewhere at the bottom of the list due to the total cost. so, upon search() (or beforehand?) i'd like to simply 'mute' the order. i don't want to disable it entirely since a user may want to subsequently choose a column to order by, but just back out the column that is currently set to order by.

thanks for any info-

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,887Questions: 1Answers: 10,140 Site admin

    If you are using server-side processing then the ordering of the data is entirely dictated by the server-side process. You can tell DataTables not to apply an order using order() and just passing in an empty array. What the server then does it up to it! In SQL if you don't apply a ORDER BY clause you often get the rows in last insert / update order for example. If there is a specific order you want then you need to have the server return data in that order.

    Allan

  • johnblythejohnblythe Posts: 92Questions: 21Answers: 2

    yo!

    got it coming in ordered from our source (Solr in this case rather than MySQL). the issue at that point was that our Total Spend column in DT was still thinking we were sorting by it so it visually showed as if we were.

    we got around it by adding the Solr relevance score as a hidden column to sort by after I had tried the empty array method. well, actually, i tried the empty array method, had no luck, posted here, then added that column to sort on, and then received the above reply. i guess i had attempted the empty array approach incorrectly?

    it was something like this if i remember correctly: dt.search(terms).order( [] ).draw(false)

  • allanallan Posts: 61,887Questions: 1Answers: 10,140 Site admin
    Answer ✓

    The code you used there looks perfect. Good to hear you have it working now.

    Allan

  • johnblythejohnblythe Posts: 92Questions: 21Answers: 2

    weird, it threw errors after i'd added it :\ oh well, all's well that ends well! thanks!

This discussion has been closed.