问题
Here's what I'm attempting to do:
I have an edit button within every row. when the user clicks on that edit button, I need to get the index of that row..but I'm not sure how exactly to do that. Anyone know how to do this? Please check out my Datatables live link below to further understand my problem and make any necessary changes.
Datatables live link: http://live.datatables.net/madadak/2/edit
Thanks!
回答1:
Change the jQuery code to be this:
$(document).ready( function () {
var table = $('#example').DataTable();
$("#example tbody").on('click', '.editButton', function() {
alert('Row index:' + $(this).closest('tr').prevAll().length );
});
} );
It starts with index 0 which I hope is what you want. I found it here if you're wondering.
来源:https://stackoverflow.com/questions/24498433/jquery-datatables-how-to-get-the-index-of-a-row-when-a-button-in-that-row-is-c