Has the sorting functions changed between version 1.x and 2.x?
Has the sorting functions changed between version 1.x and 2.x?
I have been using v1.10.20 for a while and am building new tables so I have started using v2.0.8. I essentially copied my existing table and changed the needed column load, so nothing has changed in the options the table is built.
However, the sorting of columns does not perform the same between versions and I am not sure if there is a new setting I am missing. in version 1.10 I could sort column 1, then columns 2. And the result would be column 1 keep its applied sorting, and column 2 would add to the sorting so to speak.
Now with v2, it seems to remove the previous sort and apply the new sort to the column.
I am not sure how I get the old form of sorting re applied to the new version.
More clearer example:
Initial column load
Column 1 Column 2
7 1
9 0
1 0
5.5 1
v1.10 sorting
Sort Column 1
Column 1 Column 2
1 0
5.5 1
7 1
9 0
Sort Column 2
Column 1 Column2
1 0
9 0
5.5 1
7 1
V2 sorting
Sort Column 1
Column 1 Column 2
1 0
5.5 1
7 1
9 0
Sort Column 2
Column 1 Column 2
9 0
1 0
7 1
5.5 1
This question has accepted answers - jump to:
Answers
Yes, this was an intentional change to stop a previous sort from effecting the outcome of the next sort.
Consider the situation where column 1 wasn't sorted initially. If the user selected to sort column 2 instead the display would be the same as for your "Sort Column 2" for v2.
That was not a desirable outcome, so what happens now is that on each sort DataTables will place the data in the originally loaded order and then apply the sort. It is noted in the upgrade notes here.
There isn't an option to switch back to the v1 method I'm afraid, since it is effectively a bug (the same action leading to two different states).
Sorry, I know that isn't the answer you were looking for, but the was a good reason for the change. If you want the ordering to be dependent on two different columns, use
columns.orderData
- e.g. you could use[1, 0]
on column index 1 in the above example to get the desired outcome.Regards,
Allan
I will have to see if I can roll my table back to v1.10 then. We use the sorting method in v1.10 to find problems/missing data in the data field, and we sort with different columns to do different checks, so I cant just say if this column is sorted, also add this column and this column in.
Further reading as to why old version was perferred:
We use 0 to indicate no data entered. But there are times where there are 3 or 4 options to choose from, and only 1 of those options can be selected. By sorting each row, you always bring the 0 to the top, and after you get done sorting all the columns, the rows with missing data are at the top and easy to see, which is similar to using an excel spreadsheet.
My websites, which still use version 1, have always relied on Shift-Click to sort on multiple columns, by which I mean that, after having sorted on one column, I hold shift and click on the header of another column to do a second-level sort on that column, and so on. I checked the test page I have built in view of upgrading to version 2 and this appears to still be working as usual.
Alan, please reassure me that it is still the case and that the shift-click technique is working as usual and I have simply misunderstood the above. I am a bit worried that the original poster has not mentioned shift-click.
@ma_roberge Thank you, I was unaware of the shift click. That actually returns the function to what I was looking for.
Oh yes, shift click still works and you can see that in the examples. We have a number of unit tests specifically for shift click and I consider that to be a fundamental part of how DataTables operates. Indeed, I'm wondering how I can extend it to make it work on mobile.
@minifiredragon Shift click is basically what
columns.orderData
does, just without an extra click. Great to hear that shift click does the job for you though - I was so focused on the inctracises of the sort algorithim in my previous post, I didn't even think of mentioning that!Allan