Selecting next row, next column with sorted data
Selecting next row, next column with sorted data
Link to test case: https://pastebin.com/ebt5W78V
Debugger code (debug.datatables.net):
Error messages shown: none
Description of problem:
I'm currently trying to implement selecting multiple items with Shift+Arrow Down / Shift+Arrow Up. The abovementioned test case works fine when the table is in the default position. However, when I sort the table using the arrows on the headers, it selects the next item as if the list weren't sorted (it jumps through the list).
Any idea what I'm doing wrong?
This question has an accepted answers - jump to answer
Answers
We're happy to take a look, but as per the forum rules, please link to a test case - a test case that replicates the issue will ensure you'll get a quick and accurate response. Information on how to create a test case (if you aren't able to link to the page you are working on) is available here.
Cheers,
Colin
Thanks for your response. I've hosted a testcase demonstrating the problem here: http://tobbi.bplaced.net/datatables/
Nice, that works well. I took a look, selecting "05000001" and then shift+arrow to select the next row, and on re-ordering both were still selected. Likewise, I did the same with two other rows and this also worked.
Please can you provide steps on how to reproduce,
Colin
It won't select the next column in sequence but rather the next column as if the list had not been sorted.
Where you're saying "column", do you really mean "row"?
Yes, sorry about that, I mean row.
It's hard to try, as I can't edit the code or add debug, but I suspect it would be because when you're selecting the row, in
ArrowUp
orArrowDown
, you're just adding or subtracting 1 to the row without any consideration to the ordering. It would be worth callingorder()
to see which the column is being drawn.Colin
Using order() I can indeed get the ordering of the table. However, that would likely not help me get the next index in sequence.
I'm also confused by https://datatables.net/reference/api/rows() which states that it takes an optional selector-modifier type variable.
According to the documentation here https://datatables.net/reference/type/selector-modifier it states that the default for the selector-modifier's order is "current".Which IMO means that the next row should be selected when I increase the index.
The row index is the based on the original data order not the order of the table. You can use a jQuery selector such as :eq() with the row index in the DOM. Only the rows shown on the page will be in the DOM. See this example:
http://live.datatables.net/qafujece/1/edit
Using the row index of 0 displays
Tiger Nixon
as that is the first row in the original data. Getting the first DOM row will show the first row in the DOM, for exampleAngelica Ramos
if you don't change the default sorting.Kevin
Thank you! With your help, I was able to get it working! I still think that this approach is way too complicated and that there should be an easier way.
Maybe it should be a feature request.
By feature rquest, do you mean you want to be able to select based on the row position without the
:eq()
selector? Just the index won't work since we use that for the data index, but it might be possible to have a selector modifier which will let numbers be used as position selectors rather than data index selectors. Sounds even more confusing!Allan