indexes in select/deselect does not return all row indexes as mentioned in documentation

indexes in select/deselect does not return all row indexes as mentioned in documentation

anusreemnanusreemn Posts: 11Questions: 3Answers: 0

Hi,

See indexes in http://live.datatables.net/tudofuga/37/edit

Steps to reproduce:
1. Select multiple rows, either in multiple clicks or single click with cmd
2. watch the consoled output of indexes.

Result: It is always the last selected/deselected row index even though wrapped in an Array [].

As per documentation of select,

The result is that if multiple items are selected in a single action (shift click in the os selection style for example) each item selected does not receive its own event, but rather the information about the selected items is conveyed in an array.

Can this be resolved.?

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    Use either the select.style os or multi+shift to select multiple rows, for example:
    http://live.datatables.net/heyalipe/1/edit

    Kevin

  • anusreemnanusreemn Posts: 11Questions: 3Answers: 0

    @kthorngren

    This still gives only the last made selection within indexes. I was expecting it to give back all indexes of all rows selected. Isn't that what makes sence in having it as an array.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    Answer ✓

    In my test case select the Ashton Cox row, the select event is triggered with one element in the array. Hold the shift key and select Bruno Nash. You will see an array of 5 elements. Is this what you are looking for?

    Kevin

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794
    edited November 2021

    I was expecting it to give back all indexes of all rows selected.

    The select event indexes are the indexes of the rows selected that triggered the event not all the selected rows. This seems correct as you would expect to only get information about the elements that triggered the event.

    This example shows how to get the selected rows. You can use something like this to get all the selected row indexes:

    table.rows( { selected: true } ).indexes();
    

    Kevin

  • anusreemnanusreemn Posts: 11Questions: 3Answers: 0

    Thanks, I've now fetched all the selected rows this way itself.

    From the documentation, I expected the indexes [] to have more than one values, atleast when row-selections are made together. Was checking in to see if it is a bug that can be fixed.

  • kthorngrenkthorngren Posts: 20,425Questions: 26Answers: 4,794

    Please provide the steps of row selections made together where there isn't an array of indexes. Your original example has select.style of multi which allows for multiple selections but they are made one at a time each invoking the event handler. The key is this part fo what you quoted:

    The result is that if multiple items are selected in a single action (shift click in the os selection style for example)

    Using multi doesn't support using shift click.

    Kevin

Sign In or Register to comment.