Hi, I’m creating a AG Grid with grouped columns like shown below.
I want now to change the font color of the headerName of the group title if the headerName value is included in the “important” array.
So in the example below only the header “Values” should be in a different color.
Any advise how to implement the condition function properly?
from dash import Dash, html
import dash_ag_grid as dag
import pandas as pd
def create_table():
df = pd.DataFrame({
"Setup_A": (
1, 1, 1, 2, 2, 2, 3, 3, 3,
),
"Setup_B": (
1, 2, 3, 1, 2, 3, 1, 2, 3,
),
"Values_A": (
68, 69, 67, 68, 69, 67, 68, 69, 67,
),
"Values_B": (
55, 43, 49, 49, 42, 48, 46, 41, 50,
),
"Infos_A" : (
"A", "A", "A", "B", "B", "B", "A", "A", "A"
),
"Infos_B" : (
"DAG", "DAG", "DAG", "DAG", "DAG", "DAG", "DAG", "DAG", "DAG"
)
})
header = ["Setup", "Values", "Infos"]
important = ["Values"]
columnDefs = [
{
"headerName": head,
"cellStyle" : {
"styleConditions" : [
{
"condition" : f"{important}.includes(params.value)",
"style" : {"color" : 'rgb(253, 253, 20)'}
}
]
},
"children": [
{"headerName": "A", "field": f"{head}_A"},
{"headerName": "B", "field": f"{head}_B"},
],
} for head in header
]
grid = dag.AgGrid(
id="column-groups-basic",
rowData=df.to_dict("records"),
columnDefs=columnDefs,
defaultColDef={"resizable": True},
style={"height": "600px"}
),
return grid
app = Dash(__name__)
table = create_table()
app.layout = html.Div(
table
)
if __name__ == "__main__":
app.run(debug=True)