Shift-click, multi-column sorting is not working in the following simple test case
Shift-click, multi-column sorting is not working in the following simple test case

The following is a test case very similar to the DataTables "Multi-column ordering" example, but the test case fails to allow for shift-click, multi-column sorting.
http://live.datatables.net/dogitala/2/edit
Does anyone have any idea why? And/or a work around?
FWIW, I highly doubt the issue is related to the format of the JSON data.... for obvious reasons... and because my app has a simple data structure more like the DT example mentioned above. My app does define "columns" and the data for those columns.
This question has an accepted answers - jump to answer
Answers
Thanks for the test case! You are using the following
orderData
:Column 0 has unique data so it seems like the second shift-click sorting isn't working. I changed the name
Gavin Joyce
toCedric Kelly
to highlight that it is working in this updated example. First sort by the Office column, you will see something like this:Now shift-click the Position column and you will see the two Cedric Kelly rows switch positions depending on the sorting direction.
Does this answer your question?
Would you like a different behavior?
Kevin
Alas, even in your test case it still doesn't work as I would expect. Click the "Office" column and then shift-click the "Name" column. The Name column does not change (but the Position column changes!). It easiest to recognize if the Name column is sorted in the ascending order. Clicking Name and then shift-clicking the Extension column also shows the sort fails. (etc)
It just dawned on me that I have been misunderstanding how the expected behavior should be.
I am wanting to have a default behavior where, for instance as in the test case, if Office is clicked on, it is sorted by Office, then Name. If Office is clicked on, then Name is shift-clicked, it is sorted with the before mentioned default sort... until Name is shift-clicked again... in which case it is now sorted in descending by Office (ascending) and Name descending.
Sorry for my confusion. Is there a work-around for this?
(as an aside: perhaps the "Multi-column ordering" docs and test data could speak to this issue?)
... and, btw, thank you for your clarification. I was thrown by the first column default sort.
If I am not mistaken, the DT shift-click sort implementation is a cascade of the sorts, and because there are default sorts composed of multiple columns for all of the columns, a single click then shift-click on a another columns creates a cascade of 3 or more sorts. For example, clicking the Office column and then clicking the Extn column leads to a Office-Name-Extn-Name sort. I throw in the last "-Name" more as a question, than as a statement.
Put another way, is the sort [Clicked column default columns sort results][Shift-clicked default columns sort], or is it [Clicked column sort results]][Shift-clicked columns default sort]?
In any case, I suspect that the current DT handling of the sort in the test case above will prove challenging for the end-user. Perhaps it might be a good idea to provide an option to change the behavior and allow Shift-click multi-column sorting to abandon the multi-column default behavior, and fall back on single selected column sorts. So in the above case, when Office is clicked, and then Extn is shift-clicked, the result order would be an ascending Office sort and then a secondary ascending Extn sort (just as if there were no orderDatas defining multi-column sorts). If Extn is shift-clicked again, the sort would be ascending Office, descending Extn. (I am using Extn in this example instead of the more obvious Name, because name is already in the default sort for the Office column.... but if the user had instead shift-clicked the Name column and then shift-clicked it again, it would sort in an ascending Office, then descending Name order).
Is there a work around to obtain the behavior I am desiring? Thanks!
Yes - it is a cumulative sort. So if we consider a sort on column index 2 it will actually be sorting on 2 then 0. If the user then adds column index 1 to the sort using shift click it would sort in column index order 2, 0, 1. As Kevin says, 0 contains unique values, so column index 1 will never be sorted.
There is no built in way to do what you are looking for. What I think you would need to do is listen for the
order
event listener (and remove theorderData
arrays in the init). Then check in the event handler if multi-column sorting is used or not. if not, then trigger another order action, adding your default column to the order array. If multi-column sorting is being used, then just let that run through (i.e. do nothing in the event handler).Allan