Sort asc, desc, and *rev*

Sort asc, desc, and *rev*

matthias@leisi.netmatthias@leisi.net Posts: 2Questions: 1Answers: 0

I have a datatable with a textfield, which I can sort ascending and descending. Processing happens server-side.

Now I'd like to add a third sort option, "reverse", meaning that on the server side, I'd like to sort by the reverted textstring. No problem to implement that in the SQL on the DB server, but how could I add this sorting option on the client UI?

I don't want to add this as a visible field, but it would be OK to add it as a hidden field if required.

Answers

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin

    I've always wondered if there was a valid use case for something other than ascending or descending sorting - thank you for providing it!

    Yes this is possible using the columns.orderSequence option. Just add your rev option to the array. Obviously your server-side script will need to be updated to cope with that, but that should be all that is needed on the client-side.

    Allan

  • matthias@leisi.netmatthias@leisi.net Posts: 2Questions: 1Answers: 0

    Thanks, this works perfectly!

    (The use case, if you are interested, is for the editing UI of dnswl.org. If we want to sort on domain name, we could either parse all the data then do the sorting - not feasible for close to 1 mio records - or we could simply order by reverse(domainname) which gives us almost the same effect. But we still want to retain the "forward" asc/desc sort.)

    Is there a way to indicate the "third sort order"?

    I see that the picture is referenced as https://cdn.datatables.net/1.10.10/images/sort_both.png in case of the third sort order (as opposed to sort_asc.png and sort_desc.png). I believe it would need a third "filename", as the "sort_both.png" would be needed to indicate the state "not ordered by this column".

  • allanallan Posts: 63,783Questions: 1Answers: 10,511 Site admin

    Currently no unfortunately. This is the code where DataTables adds the classes and it currently only considers asc or desc. I'll address that in the next major version which will improve the CSS class names used by DataTables.

    In the mean time, that is where you would need to put a local change in to allow the third option to be styled.

    Allan

This discussion has been closed.