Selecting next row, next column with sorted data

Selecting next row, next column with sorted data

DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0
edited May 2021 in Select

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

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0

    Thanks for your response. I've hosted a testcase demonstrating the problem here: http://tobbi.bplaced.net/datatables/

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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

  • DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0
    edited May 2021
    1. Re-order the list by clicking either of the two column headers.
    2. Select the first column, press Shift and Down to try to select the next column.

    It won't select the next column in sequence but rather the next column as if the list had not been sorted.

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395

    Where you're saying "column", do you really mean "row"?

  • DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0

    Yes, sorry about that, I mean row.

  • colincolin Posts: 15,240Questions: 1Answers: 2,599

    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 or ArrowDown, you're just adding or subtracting 1 to the row without any consideration to the ordering. It would be worth calling order() to see which the column is being drawn.

    Colin

  • DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0

    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.

  • kthorngrenkthorngren Posts: 21,322Questions: 26Answers: 4,948
    Answer ✓

    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 example Angelica Ramos if you don't change the default sorting.

    Kevin

  • DantronikMarkusDantronikMarkus Posts: 6Questions: 1Answers: 0

    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.

  • allanallan Posts: 63,489Questions: 1Answers: 10,470 Site admin

    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

Sign In or Register to comment.