Ag Grid, change column colour based on other column's value

Hi everybody, I am trying to make A green when B is “yes”. In other words, elem1 and alem 3 should be displayed with green background in Ag-Grid.

| Header A | Header B |
| elem1 | yes |
| elem2 | no |
| elem3 | yes |

This code is not working, somebody could tell me why? thanks in advance

   cellsytle_jscode = JsCode("""
    function(params) {
        if (df['Header B'].value == 'yes') {
            return {
                'color': 'white',
                'backgroundColor': 'green'
            }
        } else {
            return {
                'color': 'black',
                'backgroundColor': 'red'
            }
        }
    };
    """) 
    
    gb.configure_column("Header A", cellStyle=cellsytle_jscode)

You can access the values of other columns in the same row using params.data.{row of interest}.

So in your example it would be somthing like:

   cellsytle_jscode = JsCode("""
    function(params) {
        if (params.data.Header B == 'yes') {
            return {
                'color': 'white',
                'backgroundColor': 'green'
            }
        } else {
            return {
                'color': 'black',
                'backgroundColor': 'red'
            }
        }
    };
    """) 
    
    gb.configure_column("Header A", cellStyle=cellsytle_jscode)

You’ll likely need it to be “Header_B” instead of “Header B”. A quick way of looking at what you can access from params would be to stick a console.log(params) in before the if block.

Hope that works!