Reputation: 9668
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 to add an .active
class to a row with a given id:
table.on( 'xhr', function () {
table.row("#id_1").addClass("active");
}
(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?
Upvotes: 2
Views: 18856
Reputation: 1395
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');
Upvotes: 5