Cell background color based on cell content
Cell background color based on cell content
dmolavi
Posts: 65Questions: 0Answers: 0
For a new site I'm writing, I would like to be able to specify the background color of the table cell based on the value within that cell. For example:
value < 6, bgcolor = red
6 < value < 8, bgcolor = green
value > 8, bgcolor = red
Is this possible? The data will be gotten by JSON.
value < 6, bgcolor = red
6 < value < 8, bgcolor = green
value > 8, bgcolor = red
Is this possible? The data will be gotten by JSON.
This discussion has been closed.
Replies
The code:
{ "aTargets": [5], "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
if (sData == 'W') {
$(nTd).css('background-color', '#DFF2BF').css('color', '#4F8A10').css('font-weight', 'bold');
} else if (sData == 'D') {
$(nTd).css('background-color', '#BDE5F8').css('font-weight', 'bold').css('color', '#009');
} else {
$(nTd).css('font-weight', 'bold').css('background-color', '#FFBABA').css('color', '#D8000C');
}
} }