How do I get ids of visible rows?

How do I get ids of visible rows?

ayzayz Posts: 63Questions: 23Answers: 1

Is there a function to get the ids of currently visible rows?

I'm aware of 'start' and 'end' of page.info() but depending on how the data is sorted, I presume indexes of the visible rows cannot be assumed to be sequential.

Or is it the case that the indexes stay the same and rows simply get re-arranged?

This question has accepted answers - jump to:

Answers

  • kthorngrenkthorngren Posts: 21,448Questions: 26Answers: 4,974
    Answer ✓

    Use rows().indexes() with the selector-modifier of { page: "current" }. For example:

    var indexes = table.rows( { page: "current" } ).indexes();
    

    The each row's index is assigned when its added to the Datatable. The index does not change.

    Kevin

  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin

    There is also rows().ids() if you specifically want the id attribute of the rows, rather than the indexes. Which would be better will depend on what you are looking to do. Perhaps you could explain further?

    Allan

  • ayzayz Posts: 63Questions: 23Answers: 1

    Yes, thank you both. I'm doing this currently:

    visibleIds = tab.current.rows({ page: "current" }).ids()
    visibleIds.rows({ page: "current" }).every((rowIdx) => {...
    
  • allanallan Posts: 63,689Questions: 1Answers: 10,500 Site admin
    Answer ✓

    Line 1 isn't needed there - just do:

    tab.current.rows({ page: "current" }).every((rowIdx) => {...
    

    Allan

Sign In or Register to comment.