Feature request: enhance orderSequence option to allow going back to unsorted state

Feature request: enhance orderSequence option to allow going back to unsorted state

TablefakTablefak Posts: 31Questions: 6Answers: 0
edited May 2023 in Free community support

I was surprised to find out this isn't implemented, and nobody seems to even have asked for this before :smile:

Currently, the only acceptable values for the orderSequence option are "asc" and "desc". Which means that if the user decided to sort some column, there's no way to go back to the unsorted state. In my opinion, it would make a lot of sense to have a third value like "none" which would do this.

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406
    edited May 2023

    You can get the rows in the unsorted state by using order: index
    Not sure whether you can use it as a command to reorder the table. I am using this to export data to Excel in the unsorted state.

    https://datatables.net/reference/type/selector-modifier

    And this is from my own coding (exportOptions from the Excel export mentioned above). Works fine.

    UPDATE:
    Just checked it:
    I guess all you need to do is to pass an empty array like this:

    table.order([]).draw();
    

    That should redraw the table in index order as well.

  • TablefakTablefak Posts: 31Questions: 6Answers: 0

    Hi. Thank you for looking into it.

    From what I understood, I need to do the following:
    1. Hook into the "order" event.
    2. When it fires, determine if my column was in the last order state (e.g. "desc", if my sequence is ["asc", "desc"]).
    3. Run .order([]).draw() for that specific column.

    This looks like a lot of hacking to me. It wouldn't be very easy for me to implement that correctly. That's why I wish there was a native way to achieve this.

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    I still haven't understood your use case. Can you describe what you need to achieve? Just in plain English please.

  • allanallan Posts: 61,446Questions: 1Answers: 10,054 Site admin
    Answer ✓

    What your looking for is actually coming in DataTables 2 and has already been committed. I don't know yet when 2 will be released - there is still a bunch of stuff to do for it, but it is coming. CloudTables uses the development version of DT2 and you can see (that I think is) the behaviour you are looking for on the demo table. Click a header to sort multiple times - the third state is to revert to the unsorted state.

    Allan

Sign In or Register to comment.