I'm using Datatables and trying to highlight row(s) based on other input that can be set after the table was created. Wasn't able to use the createdrow callback and I'm not sure it is good for this purpose because it used for the creation while I need it after.
I can do it with javascript, but thought maybe there is better option with the datatables properties/function.
https://jsfiddle.net/lironco/52pcza0r/
$(document).ready( function () {
$('#myTableId').DataTable();
} );
function itemSelected(sel) {
var opts = [];
var len = sel.options.length;
for (var i = 0; i < len; i++) {
if (sel.options[i].selected) {
opts.push(sel.options[i].value);
}
}
var table = document.getElementById("myTableId");
for (var r = 0; r < table.rows.length; r++) {
if(opts.indexOf(table.rows[r].cells[0].innerHTML) >= 0){
table.rows[r].cells[0].classList.add('highlithRow');
table.rows[r].cells[1].classList.add('highlithRow');
}
else{
table.rows[r].cells[0].classList.remove('highlithRow');
table.rows[r].cells[1].classList.remove('highlithRow');
}
}
}
