add class to individual columns
add class to individual columns

Hello guys, using columnDefs I need to add <td class="table-warning"
if data == 'x' and <td class="table-success"
if data == 'y'
What's the best way to accomplish this goal?
"columnDefs": [ {
"targets": 2,
"render": function ( data, type, row, meta ) {
if (data == 'x') {return '<td class="table-warning"> ' + data + ' </td>'; //wrong!
} else if (data == "y") { return data;
} else { return data;}
}
},
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Use
createdCell
orcreatedRow
. If the data can change then userowCallback
instead.Kevin