Dash Ag-Grid: f-strings in styleConditions

Curious why this style condition works:

row_style = {
    'styleConditions': [
        {
            'condition': "params.data.date == '2023-05-14'",
            'style': {'backgroundColor': 'purple'},
        },
    ]
}

But when trying to do the same with an f-string so that today’s rows are highlighted it doesn’t seem to pick that up. Maybe there is a better way of accomplishing this?

row_style = {
    'styleConditions': [
        {
            'condition': f"params.data.date == {dt.date.today()}'",
            'style': {'backgroundColor': 'purple'},
        },
    ]
}

Thank you! I’m loving Ag-Grid.

1 Like

Hello @swilson,

Welcome to the community!

You need to wrap it is single quotes like you did in the first one. You’re missing the first one in the f string.

You probably have a console error for this as well on the browser.

Thanks, literally just caught that.

1 Like