Datatable: "style_cell_conditional" can 'else' be used with 'if'?

I am currently configuring a Dash DataTable. In regard to style_cell_conditional for column alignment, I know that it can be done in the following way:

style_cell_conditional=[
                    {
                        'if': {'column_id': 'food'},
                        'textAlign': 'left'
                    }
                ]

OR for multiple columns:

style_cell_conditional=[
    {
        'if': {'column_id': c},
        'textAlign': 'left'
    } for c in ['Date', 'Region']
]

My question is: Is it possible to have an ‘else’ statement in order to format the remaining columns?

For example:

style_cell_conditional=[
                    {
                        'if': {'column_id': 'weapon'},
                        'textAlign': 'left'
                        'else',
                        'textAlign': 'center'
                    }
                ]

I’ve not tried this but wouldn’t that just be the same as:

style_cell={'textAlign': 'center'},
style_cell_conditional=[
                    {
                        'if': {'column_id': 'weapon'},
                        'textAlign': 'left'
                    }
                ]

?

2 Likes

It works! Thank you for that. Saved me several lines of code.