I am using jQuery and datatables. I want to add a class to the TR element of a particular row. I know how to find the row. The console.dir(row);
shows the row
object and that starts with a tr
element. I can't get the jQuery selector to do anything though. What am I missing?
table = $('#resultTable').DataTable({
aaSorting: [],
ajax: {...},
columnDefs: [...],
createdRow: function (row, data, index) {
//
// if the second column cell is blank apply special formatting
//
if (data[1] == "") {
console.dir(row);
$('tr', row).addClass('label-warning');
}
}
});
DataTable().row.add() situation:
If you want to add class when using row add function in Datatables, you could get the TR-DOM from
node()
method:Also you can add class to
tr
by pass through json data that you send to datatable. It's enough that every json item hasDT_RowClass
.For example:
In this example
DT_RowId
value apply toid
attribute of anytr
tag andDT_RowAttr
value apply some custom attribute totr
tag.$('tr', row)
is looking for a tr element in the context of row, meaning it will search for a tr element inside therow
provided as context parameter.According to API, this should work
You would just have to use the createdRow
`
`