'Formatting rule to change other cells based on cell value
I'm trying in Aggrid to do the following formatting:
- if cell X has some value, then change the formatting of cells Y an Z (different columns, same row)
Is this possible to do ? Which functions from the API should I use ?
edit : alternatively, because my grid data won't be edited, I can also look for a way to simply define ahead of time of cells so they get displayed with a specific style, while other cells of the same column on different rows get displayed with another style (eg different font color)
Solution 1:[1]
Seems quite straightforward what you're trying to achieve. You need to use the cellClassRules property for your Y and Z columns, and format them appropriately, depending on the value of column X.
Here is a simple example which set the background colour of columns Y and Z to the colour specified in column X:
cellClassRules: {
'rag-red': (params) => {
return params.data.x == 'red';
},
'rag-amber': (params) => {
return params.data.x == 'amber';
},
'rag-green': (params) => {
return params.data.x == 'green';
},
},
And the definition of the css classes:
.rag-red {
background-color: lightcoral;
}
.rag-green {
background-color: lightgreen;
}
.rag-amber {
background-color: lightsalmon;
}
Demo.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | ViqMontana |
