0

So I was tasked with causing the cells of a calculated column in a list to change color per its value. Similar to conditional formatting in Excel and InfoPath. Used this little bit of jQuery… I would love to hear if this is a good solution, or if a more elegant solution can be used:

//note: I did not use variables for brevity.

$(‘table.ms-listviewtable td:nth-child(11) div’).each(function () {

if($(this).html() > “1” ){
$(this).css(‘background-color’, ‘red’);
$(this).css(‘color’, ‘white’);
}
else if($(this).html() == “1”){
$(this).css(‘background-color’, ‘yellow’);
$(this).css(‘color’, ‘black’);
}
else if($(this).html() < “1”){
$(this).css(‘background-color’, ‘green’);
$(this).css(‘color’, ‘white’);
}
});

(Visited 172 times, 1 visits today)
Add a Comment