Changing Color Of Specific Cells In A Pivot Based On Textual Condition
Sometimes you might want to change the color of your pivot columns based on a condition - for example coloring the column in green if the cell's value is equal to a specific word and red if not:

STEP 1 - ADD THE FOLLOWING SCRIPT TO YOUR PIVOT'S EDIT SCRIPT
var columns = [2, 3]; //select the date columns that should be transformed
var colors = ['green','red']; //color when true, color when false
condition_value = 'Africa' //set to the desired condition value
widget.on('ready', function(se, ev){
$.each(columns, function(index, value){
num = $("tbody tr:first").children().length - value;
var e = element;
var w = widget;
var d = dashboard;
$("tbody tr" , e).not('.wrapper, .p-head-content').each(function(){
var cell = $(this).children().last();
for (var a = 0; a < num; a++){
cell = cell.prev();
}
var cell_value = cell.text()
if (cell_value === condition_value) {
$(cell).css("background-color", colors[0]);
}
else{
$(cell).css("background-color", colors[1]);
}
});
});
});
STEP 2 - SET THE VALUES ABOVE THE LINE TO THE DESIRED VALUES
STEP 3 - SAVE THE SCRIPT, REFRESH THE WIDGET AND PRESS "APPLY"
Updated 03-02-2023
intapiuser
Admin
Joined December 15, 2022