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?
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?
Share Improve this question edited Apr 18, 2016 at 11:10 sdvnksv asked Apr 18, 2016 at 6:07 sdvnksvsdvnksv 9,71819 gold badges64 silver badges119 bronze badges 2-
3
table.row("#id_1")
may not be returningjQuery
wrapped object.. Try$(table.row("#id_1")).addClass
– Rayon Commented Apr 18, 2016 at 6:11 - Rayon, that was a very good point! You are my saviour again. Luca pleted the answer with a mention of node() too! Thank you very much! I have a lot to learn yet. – sdvnksv Commented Apr 18, 2016 at 6:20
1 Answer
Reset to default 5The 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()