Get row index of checked row

Get row index of checked row

sbarnettsbarnett Posts: 23Questions: 5Answers: 0
edited August 2011 in DataTables 1.8
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]

Replies

  • fbasfbas Posts: 1,094Questions: 4Answers: 0
    edited August 2011
    [code]
    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 )
  • sbarnettsbarnett Posts: 23Questions: 5Answers: 0
    Genius! I knew it's be simple but Javascript is quite new to me.

    Thanks fbas - much appreciated!
  • runelrunel Posts: 4Questions: 0Answers: 0
    fbas thank you for the solution! I love you man!
This discussion has been closed.