Using `orderData` applies sorting arrow styling to wrong column
Using `orderData` applies sorting arrow styling to wrong column
Hi Allan,
I hope you are doing well! I think I might have found a bug:
Description of problem:
When using columnDefs.orderData in DataTables 2.1.8, the sorting arrow icons are not toggled in the "target" column but in the (potentially hidden) column with the "orderData".
The expected result would be that the sorting arrow icons are updated in the sorted-on column, as is the case with DataTables 1.13.11.
Testcase with DataTables 2.x (nightly): https://live.datatables.net/jivalori/1/edit?html,js,output (wrong behavior)
Testcase with DataTables 1.13.11: https://live.datatables.net/biqogobi/1/edit?html,js,output (expected behavior)
Best wishes,
Tobias
Replies
See this thread with the same question. @allan will need to comment.
Kevin
Hi!
Thanks @kthorngren! Yes, this seems to be a very similar problem.
@allan, do you have an opinion on this?
For me, it clearly a bug, as simply defining different data for the sorting should not influence the actual column.
(The use case for this is a column with highly complex data (e.g. images, complex HTML, ...) for which a custom sorting algorithm isn't feasible. Then, the hidden
orderData
column will e.g. have plain numbers that are instead used for the sorting of the complex column. This has been working well, but DT2 is now adding the sorting arrow icons to the wrong column.)Best wishes,
Tobias
Yup, I can certainly see that argument. When implementing it (if I recall correctly) I was primarily thinking about multi-column sorting - when triggering ordering on one column would have the table ordered on that column plus another - in such a case it would be appropriate to implement it as it currently is.
But for ordering based on data from another column completely, as is your case here, then that isn't all that useful.
In retrospect perhaps it would have been better to do it the way discussed here. I'll look into what is involved in making that change.
Allan
Hi @allan,
Thanks for your insights here!
Now, even for this, it seems strange that the original column (which is the one where the column header is clicked), doesn't have sorting arrow icons, no?
Thanks, that would be great! As this used to work fine before, it would be great to keep that old behavior.
Best wishes,
Tobias
Agreed - something not quite right there. To be looked at! Working on Editor 2.4 at the moment and then DataTables 2.2, which this will be part of.
Allan
Following up on this - regarding the multi-column ordering, it is working as I would expect: https://live.datatables.net/jivalori/2/edit .
Moreover, I think the example you gave is a good example of why the ordering icon should be on the column(s) that ordering is applied to - the order is on the last column and that is visually shown.
I think that is all correct so far.
Where that falls apart is if the ordering column is hidden!
The solution presented in the thread Kevin mentioned I think handles that quite well, and allows for the two initial cases shown above, as well as the hidden column one: https://live.datatables.net/jivalori/3/edit .
Without introducing a new option ("iconOnOrderClickHeader"? I've no idea what' I'd call it!) I think this is a good solution. I want to keep the behaviour of v2 applying the icon to the ordering column, that is correct under all circumstances I can think of - the key is to add it as well to the original column in case the ordering column is hidden. Which this solution does.
Does that seem reasonable?
Allan
I've updated the docs to highlight this issue and how to address it.
Allan
Hi @allan,
I hope you had a great start to 2025!
Thanks for looking into this some more and for your insights!
Yes, I agree that this is a bit of an odd situation when the column with the ordering data is hidden.
I had seen the
drawCallback
idea, which also works, but it's a bit complex. But that suggestion that is now in the Docs should work well here and hopefully adding the clicked-on column to theorderData
doesn't have too many side effects on the sorting (I assume it only would for rows that are considered "equal" after sorting for the firstorderData
entry.)Best wishes,
Tobias
Hi Tobias,
Happy New year .
Yes, the only side effect would be if the first sorting column (in this case the hidden one) had the same value for cells, then a secondary sort would be done on the second column. That is probably desirable anyway.
Allan