Aggrid: Is there a way to color a row based on a column value?

Hi.

I’m using streamlit-aggrid custom component to display dataframes. I’d like to color an entire row based on a specific column’s value. I’m not sure how to do it as there are no examples provided for this. Please help.

Best wishes,

Dinesh

I figured out how to do it, thanks to code to enable other functionality not directly supported that a user posted on the Aggrid thread in Show the Community channel. The following snippet should help (I’m assuming the dataframe has a column called state, and you know about using Aggrid otherwise including imports):

            jscode = JsCode("""
            function(params) {
                if (params.data.state === 'failed') {
                    return {
                        'color': 'white',
                        'backgroundColor': 'red'
                    }
                }
            };
            """)
            
            gridOptions = gb.build()
            gridOptions['getRowStyle'] = jscode

            grid_response = AgGrid(
                df,
                gridOptions=gridOptions,
                allow_unsafe_jscode=True,
           )

Hope this helps others searching for a similar answer,

Dinesh