Issue with getting row data after a sort
Issue with getting row data after a sort

I have a datatable and am getting my row data like this:
label onclick event: onclick='openEditDialog(this)'
function openEditDialog(btnClicked) {
var selectedRow = $(btnClicked).closest('tr').index();
var tableToEdit = ($(btnClicked).closest('table').attr("id"));
var table = $("#" + tableToEdit).DataTable();
var data = table.row(selectedRow).data();
}
Data is correct before I sort, however after I sort, data becomes incorrect.
If I had a list of 1, 2, 3 and sorted to 3, 2, 1, then clicked on the row with 3 in it my data would be 1. Any idea what im doing wrong? Thanks.
Answers
Update on this, looks like because I had this in an onclick function and not inside a document.ready event handler it wasn't updating the positions of the rows?
Nevermind doesn't appear like that changed anything
Are these buttons that are in each row of the table? Not sure why the above doesn't work but here are two examples of buttons in each row and getting the data in the row clicked:
http://live.datatables.net/xijecupo/1/edit
http://live.datatables.net/qemodapi/1/edit
If you want help debugging what you have please provide a link to your page or a test case replicating the issue. This way we can see what you have and how it behaves.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Kevin
Thank you for your response.
I changed var selectedRow = $(btnClicked).closest('tr').index();
to match your example:
var selectedRow = $(btnClicked).closest('tr');
It appears to be working now, not sure why though.