Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the row number of selected row of jquery datatable

I am trying to get the row number from datatable and pass in to some update function.Some time it giving row number as [Object object] Here is my code:

var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'tr', function () 
{
var idx = table.row( this ).index();
alert(idx);//Some times it alerts [Object object] 
}
like image 241
chaya Avatar asked Jan 09 '23 21:01

chaya


1 Answers

You could use

$('#example tbody').on( 'click', 'td', function () 
{
    var tr = $(this).closest("tr");
    var rowindex = tr.index();

     alert(rowindex);
});

this way you'll have the index value of the row.

like image 188
Telmo Silva Avatar answered Jan 29 '23 21:01

Telmo Silva