Conditional formating numerical column

Hi all,

I’ve been reading a lot of documentation and discussions about conditional formatting of datatable however I am able to solve my problem. I am trying to format negative cells in one column but is seems to ignore the filter_query condition and formats all cells in that row. Could anyone point out where is my mistake?

Thanks a lot

app = dash.Dash(name=__name__)

external_stylesheets = [

app = dash.Dash(__name__,
app.config.suppress_callback_exceptions = True

app.layout = dash_table.DataTable(id='table-produto',
                             columns=[{"name": i, "id": i} for i in df.columns],
                             style_cell={'padding': '5px'},
                             n_fixed_rows={'headers': True, 'data': 0},
                                 'backgroundColor': 'white',
                                 'fontWeight': 'bold'
                                 "if": {'column_id': 'Lucro Bruto',
                                        'filter_query': '{Lucro Bruto} < 0'},
                                 "backgroundColor": "#3D9970",
                                 'color': 'white'

if __name__ == '__main__':

I think you just need to change filter_query to filter. In my case, I also set the filter (as you defined) on the style_cell_conditional parameter (vice style_data_conditional).

Also, based on the documentation,

To use even/odd or other styling based on row_index you must use style_data_conditional

I suspect the use of style_data_conditional much include a reference to the row index, but I’m not certain.

After reviewing the documentation online, I cannot see anything wrong with your filter - as it matches examples shown. So, the online examples could be outdated if you are using the latest version of dash, or the filter conditional statement may not like spaces in the column name. I doubt the likelihood of the space in the column name being the problem, but it could be worth testing.


You are right. It was a version issue. I thougth I was using the 1.0.0 version but it was actually one before. What is very strange is that when I do a pip freeze requirements.txt it turns out that the version is 1.0.0 however when I check the version with dash.version it shows 0.46.
Anyway, thesyntax with filter worked!!
Thank yoou!

1 Like

One way this could happen is that if you have multiple environments pip could actually be picking up a Python from a different environment. To reduce the chance of this happening you can call python -m pip, e.g.

python -m pip freeze

It may however be a different issue that you’re having.

I don’t know why it is showing me the version 1.0.0 in requirements. In all my envs I have older versions installed. I tried with python -m pip and is also showing the version 0.43.