Setting AG Grid background color with range of values

This is the normal solution I have when it comes to highlighting cell color. However, How do I make it so that the reds and green are highlighted at different shades based on how positive/negative they are?

gd= GridOptionsBuilder.from_dataframe(display_df)
cellstyle_jscode = JsCode("""
function(params){
    if (params.value == '0') {
        return {
            'color': 'black', 
            'backgroundColor': 'orange',
        }
    }
    if (params.value < '0') {
        return{
            'color': 'white',
            'backgroundColor': 'red',
        }
    }
    if (params.value > '0') {
        return{
            'color': 'white',
            'backgroundColor': 'green',
        }
    }
}
""")
gd.configure_pagination(enabled=True)
gd.configure_columns(display_df, cellStyle= cellstyle_jscode)
grid_options = gd.build()

Screenshot 2022-03-17 135847

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.