admin管理员组文章数量:1355645
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()
本文标签: javascriptDatatables Select row with given IDStack Overflow
版权声明:本文标题:javascript - Datatables: Select row with given ID - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743945594a2566346.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论