Changing background color of rows in a pivot based on condition
Introduction
Sometimes you might want to change the color the rows of your pivot based on a numeric condition - for example coloring the row in green if the revenue is over or equal to a certain value, and red if it's below it:
Steps
Step 1 - Add the following script to your pivot's edit script
var condition_number = ;
var color_up = "#339933";
var color_down = "#ff6666";
widget.on('ready', function(){
setTimeout(function(){
$("tbody tr", element).each(function(){
if(parseInt($(this).children(".p-value").children().text().replace(',','')) >= condition_number){
$(this).css("background-color", color_up);
}
else {
$(this).css("background-color", color_down);
}
$(this).children().last().remove();
});
$(".p-alternate").removeClass("p-alternate");
//$(".phantom").remove();
}, 1)
});
Step 2 - Set condition_number to the desired value
Step 3 - Save the script, refresh the widget and click "Apply"
*You can change the colors of the conditional by changing the values of color_up and color_down
Please sign in to leave a comment.
Comments
3 comments