I am creating the rows of a table with the DataTable Jquery library and I want to add a style to a row, I generate the rows in this way.
// idTabla es una variable que la envió desde la vista **var idTabla = DataTable();**
idTabla.row().clear();
for (var i = 0; i < datos.length ; i++) {
if (datos[i].estado == '1') {
var icon = "<i class='fa fa-check' id='loadState"+datos[i].id+"'></i>";
}else{
var icon = "<i class='fa fa-ban' id='loadState"+datos[i].id+"'></i>";
}
//
idTabla.row.add([
datos[i].id,
datos[i].nombre,
"<div class=' text-center col-md-12'><a href='#' id='editarObservacion"+datos[i].id+"' class=' ' onclick='activarDesActivarElect(\""+datos[i].id+"\", \"2\", \"loadState"+datos[i].id+"\", \""+id+"\", \""+datos[i].estado+"\")'> "+icon+" </a></div>"
]);
}
idTabla.draw(true);
The intention of the above is that when you enter the else add a different font color to the entire row and in this way identify the data that enters with the status != 1
You can define a variable before the for and give it (or not) a value depending on the conditional, finally get the current row and add a class with jQuery:
In the end I managed to add the class in this way, I leave the code below to serve someone who ever has this same question
a more practical way to add information, simply with the attr method you add the class in the column you want. searching inside find('td').eq('column you want to implement the class or event').