✊🏿 Black Lives Matter. Please consider donating to Black Girls Code today.
⚡️ Concerned about the grid? Kyle Baranko teaches how to predicting peak loads using XGBoost. Register for the August webinar!

To give more than two colors in the dash datatable headers

Hi,

Anyone knows how to give more than two colors to the headers??


I tried with below logic but got incorrect syntax
style_header={
‘backgroundColor’: ‘rgb(230, 230, 230)’,
‘fontWeight’: ‘bold’
},
style_header_conditional=[
{
‘if’: {‘column_id’: c},
‘backgroundColor’: ‘rgb(255, 191, 0)’,
‘color’: ‘#000000
} for c in [‘Working Days’,‘Total Work Hrs’,‘PTO’,‘Total Work Hrs Available’,‘Revenue’],

                          {
                          'if': {'column_id': d},
                          'backgroundColor': '#51f542',
                          'color': '#000000'
                      } for d in ['Actual Hrs spend','Actual cases coded','ROI'],
                          ],

Hi @Allan, and welcome to the Dash community :slight_smile:

try this syntax:

style_header_conditional=(
        [
            {
                "if": {"column_id": c},
                "backgroundColor": "rgb(255, 191, 0)",
                "color": "#000000",
            }
            for c in [
                "Working Days",
                "Total Work Hrs",
                "PTO",
                "Total Work Hrs Available",
                "Revenue",
            ]
        ]
        + [
            {"if": {"column_id": d}, "backgroundColor": "#51f542", "color": "#000000"}
            for d in (["Actual Hrs spend", "Actual cases coded", "ROI"],)
        ]
    ),
2 Likes

Thanks alot @AnnMarieW :slight_smile:
It worked

1 Like