Left-to-Right sorting
Left-to-Right sorting
First of all, hats off for this wonderful tool. It's made life so much easier!!!
I have a situation where I need to render a table using Datatables. However, I need to be able to sort it horizontally (left to right) instead of vertically (top to bottom). Is there any way I can do this?
Illustration: Columns are A,B,C,D,E. Rows are R1,R2,R3,R4...R30. I don't want to sort A to E, but I do want to sort any one of R1 to R30 so that A-E gets rearranged. For instance, for R1, the ascending order of values might be A,E,D,B,C and for R2's values, it might be D,E,B,A,C. I should be able to click on a row index (first column in that row) and see my columns reordered. (Default is rows being reordered)
Update: I found this example for horizontal sorting Sorting Table Columns with jQuery Table Sorter, but how do I get this to work with datatables?
Answers
No, this isn't something that datatables offers, however, would you be able to link me to the page regarding horizontal sorting with jQuery tablesorter you were talking about.
Would be interested to see it so we can consider it for the future.
Thanks
Tom
Hi Tom,
There's a jsfiddle that should give you an idea of what I am shooting for: https://jsfiddle.net/qjp8Lnam/7/
It would be great if I can keep column 1 constant (similar to how the thead elements stay constant with sort state updated) and reorder from column 2 onwards.
Thanks,
SR
Hi Tom,
Managed to get it done. You can see the code here: https://jsfiddle.net/rsreeram84/tnozsp5s/
It keeps column 1 constant, has toggled sort and can process numeric and non-numeric comparisons.
And if you don't mind me saying it, you're all friggin' geniuses for coming up with colReorder!
Thanks,
SR
That's very clever - nice one and thank you for sharing this with us!
I've bookmarked this so I can come back to it and see how we might integrate this sort of behaviour in future.
Allan
Hi Allan please consider adding left to right sort in a future version. I was hoping for a simple way to reverse the table left to right but holding the first column. In the attached image, I would like it reversed, so it starts with the most recent dated column is left-most next to the song label.
Thanks,Jeff