Reputation: 433
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]
}
Upvotes: 4
Views: 24369
Reputation: 2111
$(document).ready(function () {
$("#example ").dataTable().find("tbody").on('click', 'tr', function () {
alert(this.rowIndex);
});
});
Upvotes: 0
Reputation: 335
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.
Upvotes: 9