Deka87 Deka87 - 6 months ago 6x
Javascript Question

Datatables: Select row with given ID

I've set up a datatables plugin and created a new table from an JSON file:

var table= $("#mytable").DataTable({

ajax: "list.json",
columns: [
{"data": "name"},
{"data": "location"},
{"data": "date"}

Now I want a add an
class to a row with a given id:

table.on( 'xhr', function () {

(the id's for the rows has been defined during the plugin setup and are in place). However, I get this error:

undefined is not a function

like it can't find a row with this ID, however I do have it. Any ideas?


The Datatables .row() method doesn't return a DOM Node, you need to get it with .node() after selecting it.

var row = table.row("#id_1").node(); $(row).addClass('active');

Datatables .row()

Datatables .node()