chaya
chaya

Reputation: 433

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] 
}

Upvotes: 4

Views: 24369

Answers (2)

vikrant singh
vikrant singh

Reputation: 2111

    $(document).ready(function () {
    $("#example ").dataTable().find("tbody").on('click', 'tr', function () {
        alert(this.rowIndex);
    });
});

DEMO

Upvotes: 0

Telmo Silva
Telmo Silva

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

Related Questions