Get row index of checked row
Get row index of checked row
sbarnett
Posts: 23Questions: 5Answers: 0
I have a table with a column of checkboxes.
I can get the value of the checkboxes but I can't find a way to get the row index of the checked rows so I can get the data out of them.
Here is the code:-
[code]
$('#importbutton').click( function () {
$('input:checked', importTable.fnGetNodes()).each(function(){
var rowIndex = < how do I get the row index? >;
alert(importTable.fnGetData(rowIndex));
} );
}
[/code]
I can get the value of the checkboxes but I can't find a way to get the row index of the checked rows so I can get the data out of them.
Here is the code:-
[code]
$('#importbutton').click( function () {
$('input:checked', importTable.fnGetNodes()).each(function(){
var rowIndex = < how do I get the row index? >;
alert(importTable.fnGetData(rowIndex));
} );
}
[/code]
This discussion has been closed.
Replies
var rowIndex = importTable.fnGetPosition( $(this).closest('tr')[0] );
[/code]
use closest to get first (closest) ancestor
http://api.jquery.com/closest/
(note: passing a TR to fnGetPosition get's a single integer for the row index. if you use a TD, you will get an array for the row position, col position, and col position (ignoring hidden cols) http://www.datatables.net/ref#fnGetPosition )
Thanks fbas - much appreciated!