Want to add a class to conditionally
Want to add a class to conditionally
I'm populating my table dynamically using fnAddData. What I need to do is add a class to the tag if one of the row's field's has a certain value (in this case, the field is 'status', and I need to add a class to the row if the status is 'inactive'). I've tried digging around the forums and the API but couldn't find a function that does this (fnCreatedRow doesn't seem particularly suited to this case).
Hoping someone can point me in the right direction. Thank you!
Hoping someone can point me in the right direction. Thank you!
This discussion has been closed.
Replies
For now, I think I can go with organicspider's solution, it works really well with only some minor drawbacks I can definitely work with (maybe I'll just hide that particular column?). But if anyone has a solution that can add a class to the row without being dependent on the data being displayed on the table, please let me know! Many thanks.
Allan
Allan
I had implemented conditional formatting of a cell by using fnCreatedCell as given below. I believe you have to similarly add class to tr element (nTr).
[code]
"aoColumns": [
{ "sTitle": "Type", "mData" : "10"},
{ "sTitle": "Severity", "mData" : "5",
"fnCreatedCell": function(nTd, sData, oData, iRow, iCol)
{
switch(sData)
{
case 1:
$(nTd).addClass('alertSeverityLow');
$(nTd).text("Low");
break;
case 2:
$(nTd).addClass('alertSeverityMedium');
$(nTd).text("Medium");
break;
case 3:
$(nTd).addClass('alertSeverityHigh');
$(nTd).text("High");
break;
case 4:
$(nTd).addClass('alertSeverityCritical');
$(nTd).text("Critical");
break;
}
}
}
]
[/code]
Allan