Click listener triggering before row selection registers

Click listener triggering before row selection registers

warpspeed10warpspeed10 Posts: 3Questions: 1Answers: 0

I want to get information about the table row a user clicks on, so I set up a click listener on my table.

$('#my-table').on( 'click', 'tbody tr', function () {
let selectedRows = $scope.rosterTable.rows( { selected: true } ).data();
console.dir(selectedRows);
} );

The problem I am seeing is when the listener fires, it sees no rows with {selected: true} yet so it prints an empty array. Clicking the same row again prints the row like I would have expected the first time, because the "selected" class has finally registered.

Is there any way for me to catch the event of row/multi-row selection only after the selected class has finished being applied to those table rows?

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

  • kthorngrenkthorngren Posts: 21,261Questions: 26Answers: 4,934
    Answer ✓

    See if the select event will work for you.

    Kevin

  • warpspeed10warpspeed10 Posts: 3Questions: 1Answers: 0

    Here is the codepen. https://codepen.io/erichimm/pen/bGqaZXm?editors=1111

    You can see in the console, on the first click, no data is printed. Then when you unclick a row, data is finally printed.

  • warpspeed10warpspeed10 Posts: 3Questions: 1Answers: 0

    Thanks kthorngren. This is just what I was looking for.

Sign In or Register to comment.