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

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
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
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
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
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
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
for asc
for desc
how can we avoid that.
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.
I am using the below version in my case
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
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
https://live.datatables.net/voyikewe/1/edit
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
Hmmm ... I am not getting how this would address @sant527 's issue.
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:
That happened in 1.x because the sorting in the table wasn't independently deterministic.
Allan