Change sort order after search
Change sort order after search
In my application, I am using server-side AJAX calls to display a DataTable. Column searches are using standard SQL, but the full-text search at the top is using a MATCH protocol that also returns a relevance value. I've included the relevance in the return object, but I want to be able to automatically change the sort order to the relevance column when, and only when, the user enters a search term in that box. Is there a way to do it? I tried using the search.dt event, but it replaces the entire search API and then doesn't make the server call.
EDIT: I managed to get a DataTables live example working without the server side. Hopefully it will give you an idea of what I'm trying to do.
This question has accepted answers - jump to:
Answers
Edited original post...now there's a live example at http://live.datatables.net/xaxutehu/1/
Have you tried binding an event handler to that input that will use
order()
to change the order when the user enters search data? You would probably want to check the current order applied (again withorder()
) to make sure you aren't setting the order unnecessarily.Allan
Sorry, I inadvertently clicked "No" for the question being answered. I'm going to test this when I get to work and see if I can make it work. It didn't work before, but I think I missed a step...
That did it! I added the following code which made it so the search sorts by relevance, but then lets the user select other sort columns:
I'm not sure how to go back and fix my accidental click, though. I want to change your answer to "yes it answered the question".
Thanks!
Unfortunately there isn't a way to do that without hacking around int he database, so I've just marked your own answer as the correct on.
Good to hear you got it working :-)
Allan