balajivaishnav
balajivaishnav

Reputation: 2893

get selected row Id from jquery datatable version 1.9.4

Sorry this may be a duplicated question, but couldn't able to find the solution any where in the web as well as in StackOverflow

Problem

I need to get the selected row id from jquery data table

My code what I have tried

$.each($("#myDataTable").dataTable().fnGetNodes(), function (i, row) {
                var id = $(this).attr("id");
                   console.log(id)
            });

The selected TR has the class row_selected selected

class="even row_selected selected"

So I need to get the id of the selected row based on this selected class, please help in solving this issue

Upvotes: 1

Views: 1889

Answers (1)

Gyrocode.com
Gyrocode.com

Reputation: 58870

Use $() API method to perform a jQuery selector action on the table's TR elements.

For example:

$("#myDataTable").dataTable().$("tr.selected").each(function(){
   var id = $(this).attr("id");
   console.log(id);
});

Upvotes: 1

Related Questions