Click listener triggering before row selection registers
Click listener triggering before row selection registers
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
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
See if the
select
event will work for you.Kevin
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.
Thanks kthorngren. This is just what I was looking for.