Change row background color based on different column data

Change row background color based on different column data

nettlesdnettlesd Posts: 22Questions: 5Answers: 0

Anyone know how to change the background color based on different column data?

This works great for changing the color for one value but what if you have multiple values?
$(document).ready(function() {
var oTable = $('#example').dataTable();

// Filter to rows with 'Webkit' in them, add a background colour and then
// remove the filter, thus highlighting the 'Webkit' rows only.
oTable.fnFilter('Webkit');
oTable.$('tr', {"filter": "applied"}).css('backgroundColor', 'blue');
oTable.fnFilter('');
} );

Let's say I have a column and it's values can be "Webkit", "Javascript", "HTML", "XML" and "Other". I want the rows for "Webkit" to be green, red for "Javascript", blue for "HTML" and so on. Only "Other" should not have a background color.

How would you do that? Adding the above code twice or multiple times doesn't work.

This discussion has been closed.