When all row values are same for a column sorting should not alter the rows

When all row values are same for a column sorting should not alter the rows

sant527sant527 Posts: 6Questions: 1Answers: 0

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

I am using datatables.

I have columns like id, reg_year, ....

now reg_year for all rows is 2024

when i click on the reg_year header i expect that the rows dont change their order or maintain their current order.

BUt instead the rows are getting sorted by id column

I havent mentioned any sort order

how to stop this behaviour

Answers

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429

    I did the same with one of my data tables - and it worked as expected: No change for the sort order when ordering by a column that only has one identical value in all rows.

    I tested with and without initial sort order: same result.

    Please post a test case showing the issue as per the forum rules. Thanks!
    https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429

    I've just created a very simple test case by renaming a couple of people in this example to "John". Then I filter the table for "John".

    Surprisingly it shows the same ordering behavior that you have as well. Something must have changed in Data Tables 2?!

    https://live.datatables.net/nekihesu/2/edit

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429

    Yes, it seems to be a Data Tables 2 issue.

    Here is a test case that uses the dt-versions I use myself - and it works.

    Just filter for "John" and order the column: Everything stays unchanged!

    https://live.datatables.net/badaseza/2/edit

  • sant527sant527 Posts: 6Questions: 1Answers: 0

    Thanks a lot for immediately giving your response. Really appreciate.

    I checked your live thing and filter john and see when sorting the other rows keep changing. whats the datatables version you are using, i saw its nightly related. is this the latest

  • sant527sant527 Posts: 6Questions: 1Answers: 0

    I got it, when we are sorting its showing based on the html order

    https://live.datatables.net/mizilete/1/edit

    I have kept only few and now the ordering is based on their order in the html

  • sant527sant527 Posts: 6Questions: 1Answers: 0
    edited April 24

    for asc

    for desc

  • sant527sant527 Posts: 6Questions: 1Answers: 0

    how can we avoid that.

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429
    edited April 24

    The nightly version is the latest. The latest official version is 2.2.2. There it doesn't work either.

    Enter "John" to filter and then order the "name" column.

    Testcase with 2.2.2 (not working)
    https://live.datatables.net/fidijudu/1/edit

    Testcase with 1.11.5 (working)
    https://live.datatables.net/jogusoxa/1/edit

    @allan could you take a look at this please.

    In the final DT 1 version (1.13.11) it was still working:
    https://live.datatables.net/juyagisu/1/edit

    In DT 2.0.0 it didn't work any longer.

  • sant527sant527 Posts: 6Questions: 1Answers: 0

    I am using the below version in my case

    /*
     * This combined file was created by the DataTables downloader builder:
     *   https://datatables.net/download
     *
     * To rebuild or modify this file with the latest versions of the included
     * software please visit:
     *   https://datatables.net/download/#bs5/jszip-3.10.1/dt-2.2.1/b-3.2.0/b-html5-3.2.0/sl-3.0.0
     *
     * Included libraries:
     *   JSZip 3.10.1, DataTables 2.2.1, Buttons 3.2.0, HTML5 export 3.2.0, Select 3.0.0
     */
    
    /*!
    
  • allanallan Posts: 64,324Questions: 1Answers: 10,622 Site admin

    What you are seeing is actually correct and expected. It is a "stable" sort so that the order is 100% deterministic for a single sorting action.

    Prior to DataTables 2 sorting column X and then column Y could result in a different order in the table than just sorting by column Y. That I considered to be wrong and 2 fixed that (this is the code that implements that).

    I do understand the behaviour from before could be desirable in some cases, but in other cases it was the source of bugs and had to be addressed.

    The way to handle it is that if you want multi-column ordering, it needs to be explicitly set with columns.orderData: https://live.datatables.net/mizilete/2/edit .

    Allan

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429

    There is an option "columns.orderable" to turn ordering on and off
    https://datatables.net/reference/option/columns.orderable
    but there is nothing in the api like this.
    "columns().orderable()" only allows for checking whether a column is orderable or not. You cannot turn ordering on or off with it.
    https://datatables.net/reference/api/columns().orderable()

    If the latter was possible I'd have a solution for the issue
    https://live.datatables.net/voyikewe/1/edit

    I could turn ordering off for columns that only have one value ... but I can't. Hence I only make the sorting arrow disappear for those columns :neutral:

    https://live.datatables.net/voyikewe/1/edit

  • allanallan Posts: 64,324Questions: 1Answers: 10,622 Site admin

    Yeah, dynamically enabling ordering on a column is not something that DataTables offers. It isn't a request that comes up very often!

    The correct way to address the issue at hand is to use the multi-column ordering features.

    Allan

  • rf1234rf1234 Posts: 3,108Questions: 90Answers: 429

    The correct way to address the issue at hand is to use the multi-column ordering features.

    Hmmm ... I am not getting how this would address @sant527 's issue.

  • allanallan Posts: 64,324Questions: 1Answers: 10,622 Site admin

    I might has misunderstood! I'm reading it as when sorting on the second column, the first column should be sorted as well (since the second column contains all the same values). Is that not correct? @sant527 - perhaps you can clarify? I'm basing that on:

    when i click on the reg_year header i expect that the rows dont change their order or maintain their current order.

    That happened in 1.x because the sorting in the table wasn't independently deterministic.

    Allan

Sign In or Register to comment.