What Operator can I use for NOT BLANK in String/Text type of DataTable Conditional Formatting?

Hi there,
I am trying to set a conditional logic in DataTable that the cell is NOT blank in the conditional formatting logic.
The logic operator is blank is working perfect, however, when I was trying to use != blank or ne blank for the string/text type, none of these is working. Can anybody please help how to set an opposite way of the logic “NOT BLANK” meaning there are at least 1 letter in there?

style_data_conditional=( [{
                          'if': {
                                'filter_query': '({num-col1} > {num-col2}) and ({str_col} != blank)',
                                'column_id': 'str_col'
                                },
                          'backgroundColor': 'tomato',
                           'color': 'white'
                          } 
                       ] )

Hi @XMan and welcome to the Dash forum :slightly_smiling_face:

It looks like is blank is supported, but “not blank” isn’t.

You could do this by splitting the conditions into 3 steps. First is to style the entire column, then style for ({num-col1} > {num-col2}), then style the is blank

Here is an example:

style_data_conditional=(
        [
            {
                "if": {"column_id": "str_col"},
                "backgroundColor": "blue",
                "color": "white",
            },
            {
                "if": {
                    "filter_query": "({num-col1} > {num-col2})",
                    "column_id": "str_col",
                },
                "backgroundColor": "tomato",
                "color": "white",
            },
            {
                "if": {
                    "filter_query": "{str_col} is blank",
                    "column_id": "str_col",
                },
                "backgroundColor": "yellow",
                "color": "white",
            },
        

Hi @AnnMarieW - Thank you so much for your help. I used your approach to have two conditions and the 2nd one is basically using what’s supposed to be correct by using is blank changing the background colour back to white and font in black. It is just a little bit over complicated.

Do you think we can raise a request to add in not blank as a new operator to use in dash? It will be way much easier and I am pretty sure this is a common requirement to others too.

Thanks again!

2 Likes

More generally, I think expanding the filtering syntax to include not operator in addition to the current and and or operators would at least allow creation of appropriate is not blank (as well as other complex negation logic) via callbacks.