Knowledge Base Article

Color the cell based on the value

Here is the script on how to color the Pivot cell based on the value of this cell.
For example color the cells that contains the value "True":
//Text column formatting
widget.on('ready', function(se, ev){

var evalCol = 12; //fidx val of column to evaluate
var formatCol = $('td.p-dim-member[fidx='+evalCol+']'); //jquery pull entire eval column into array

$.each(formatCol, function(a, b){ //function to loop through array

if(this.textContent == 'True'){ //evaluate text conent of each cell in column's array. note: need to use JavaScript this instead of JQuery $(this), since textContent is a JavaScript attribute.
$(this).css('background-color','#32CD32); //set conditional styling
}
});
});
Updated 03-02-2023

1 Comment

  • Hi, this looks like it does exactly what I need, but I'm not familiar enough with scripting in Fusion to make use of what you've written.  Currently I'm looking at a value column in a widget and examining my conditional formatting options but of course the default options are only applicable to numerical columns. 

    I'd like to implement your script which I am guessing means copying it to a file and saving it somewhere?  But I'm not familiar with that process.  I have successfully installed a plugin once before but at that time I had a folder available which contained a plugin.json file and a .js file.  Is that how this works?  

    Thanks in advance.