nicolaskruchten / pivottable

Open-source Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.
https://pivottable.js.org/
MIT License
4.36k stars 1.07k forks source link

text-based colorScaleGenerator #1103

Open avenue19 opened 5 years ago

avenue19 commented 5 years ago

I have a table in which I need to color the cells' background based on content. I'm trying to write a custom discrete colorScaleGenerator based on literal text or a pattern. I tried like this, but apparently I'm off-track:

colorScaleGenerator: function(values) {
    return function(value) {
        if (value === 'open.new') { return "#9FD3E8"; }
        else if (value === '') { return "#BFBFBF"; }
        else if (value.match(/\d{4}-[wW]\d{1,2}/)) { return "#9FD3E8"; }
        else return "#ffffff";
    };   
}

Is there a way?

mafia99 commented 5 years ago

I am also trying to do something similar. I was thinking about somehow using forEachMatchingRecord in onRefresh. But not sure if that will work. Have you been able to find a solution for that.