How to set multiple style cell conditions

Hi,

I’m trying to set up multiple style cell conditions for the dash data table,

Where the component is defined I try something that looks like this;

style_cell_conditional =[         
       {
            'if': {'column_id': c},
            'textAlign': 'left'
        } for c in params,
       {
            'if': {column_id': 'test'},
            'testAling': 'center'
       }
]

If I remove the second ‘if’

       {
            'if': {column_id': 'test'},
            'testAling': 'center'
       }

It will work.

But I also want to define the second and more.

It is not allowed and will return an error, what is the best way to do something like this?

Try something like this:

style_cell_conditional =[         
       {
            'if': {'column_id': c},
            'textAlign': 'left'
        } for c in params
    ] + [
       {
            'if': {column_id': 'test'},
            'testAling': 'center'
       }
    ]

Basically, you just need to append the last if to the list comprehension.

1 Like