# Datatable style\_data\_conditional for empty strings

**URL:** <https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251>\
**Category:** Dash Python\
**Created:** [September 5, 2019, 2:20pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251 "2019-09-05T14:20:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![henry.k.turner](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@henry.k.turner](https://community.plotly.com/u/henry.k.turner)\
**Post date:** [September 5, 2019, 2:20pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/1 "2019-09-05T14:20:06Z")

</div>

Hi all,

I have a data table for which i would like blank entries to be highlighted in red. I’m trying to use the style\_data\_conditional combined with the “filter\_query”. I have an example of this working where in the column “Process” and cells with “Process 1” are highlighted, and in “Time/s” any columns with the number 5 are highlighted:

style\_data\_conditional=[  
{  
“if”: {  
‘column\_id’:‘Process’,  
“filter\_query”: ‘{Process} eq “Process 1”’  
},  
“backgroundColor”: “red”,  
},  
{  
# “if”: {  
# ‘column\_id’:‘Task’,  
# “filter\_query”: ‘{Task} eq 5’  
# },  
# “backgroundColor”: “red”,  
},  
{  
“if”: {  
‘column\_id’:‘Time/s’,  
“filter\_query”: ‘{Time/s} eq “5”’  
},  
“backgroundColor”: “red”,  
},  
],

 ![Selection_024](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/13fc7b54742fbf06dcf3c791e94a3810d305cd54.png)

However I can’t get this to work for the blank cells. When I try to filter\_query “” it returns the error message:

"unable to evaluate target: syntax tree is invalid for query={Task} eq “” "

style\_data\_conditional=[  
{  
“if”: {  
‘column\_id’:‘Process’,  
“filter\_query”: ‘{Process} eq “Process 1”’  
},  
“backgroundColor”: “red”,  
},  
{  
“if”: {  
‘column\_id’:‘Task’,  
“filter\_query”: ‘{Task} eq “”’  
},  
“backgroundColor”: “red”,  
},  
{  
“if”: {  
‘column\_id’:‘Time/s’,  
“filter\_query”: ‘{Time/s} eq “5”’  
},  
“backgroundColor”: “red”,  
},  
],

Any help for highlighting the blank cells would be greatly appreciated!

Thanks,

Harry

---

<div class="post-metadata">

**Author:** ![Marc-Andre](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Marc-Andre](https://community.plotly.com/u/Marc-Andre)\
**Post date:** [September 5, 2019, 3:02pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/2 "2019-09-05T15:02:46Z")

</div>

You just stumbled across another bug where it’s currently impossible to create a filter on an empty string.

Here’s a bogus example that works (with the fix)

Issue has been opened here: [https://github.com/plotly/dash-table/issues/569](https://github.com/plotly/dash-table/issues/569)

```auto
import dash

from dash_table import DataTable

app = dash.Dash( __name__ )

app.layout = DataTable(
    id='table',
    columns=[{
        'name': x,
        'id': x,
        'selectable': True
    } for x in ['a', 'b', 'c']],
    data=[{
        'a': str(x) if x % 2 == 0 else '',
        'b': x if x % 3 == 1 else '',
        'c': str(x*x) if x % 4 == 2 else ''
    } for x in range(0,100)],
    style_data_conditional=[{
        'if': {
            'column_id': x,
            'filter_query': '{{{}}} eq ""'.format(x)
        },
        'backgroundColor': 'pink'
    } for x in ['a', 'b', 'c']]
)

if __name__ == ' __main__':
    app.run_server(debug=True)

```

 ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/ef6777dd5118d4fdee71ecfcfbc1da9ed8ccba82.png)

---

<div class="post-metadata">

**Author:** ![Marc-Andre](https://avatars.discourse-cdn.com/v4/letter/m/e19b73/32.png) [@Marc-Andre](https://community.plotly.com/u/Marc-Andre)\
**Post date:** [September 5, 2019, 5:16pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/3 "2019-09-05T17:16:25Z")

</div>

Just confirming this has been [fixed](https://github.com/plotly/dash-table/pull/570) and will be in the next release (`dash==1.3.0`, `dash-table==4.3.0`)

---

<div class="post-metadata">

**Author:** ![henry.k.turner](https://avatars.discourse-cdn.com/v4/letter/h/a183cd/32.png) [@henry.k.turner](https://community.plotly.com/u/henry.k.turner)\
**Post date:** [September 6, 2019, 8:28am UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/4 "2019-09-06T08:28:43Z")

</div>

Awesome! thank you very much!

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [August 5, 2024, 10:09pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/6 "2024-08-05T22:09:42Z")

</div>

I used `{column} != ""` but my whole column became red instead of only those cells. The goal was to red only non-empty cells. (`column` is the column id)

I installed dash yesterday with the latest version.

---

<div class="post-metadata">

**Author:** ![tbillah](https://avatars.discourse-cdn.com/v4/letter/t/d6d6ee/32.png) [@tbillah](https://community.plotly.com/u/tbillah)\
**Post date:** [August 5, 2024, 10:12pm UTC](https://community.plotly.com/t/datatable-style-data-conditional-for-empty-strings/28251/7 "2024-08-05T22:12:12Z")

</div>

I just hacked it by using `{column} > ""`.
