I am entering filter queries with a separate input box. I see that I am able to successfully enter the query and it filters the table as expected. However, clearing the filter_query property on click of Clear Filter button does not remove text from the column filter.
In the below screenshot: Query is applied successfully.
After Clicking Clear Filters button - table is no longer filtered, but " eq Afghanistan" remains in column filter in table:
app.layout = html.Div([
dcc.RadioItems(
id='filter-query-read-write',
options=[
{'label': 'Read filter_query', 'value': 'read'},
{'label': 'Write to filter_query', 'value': 'write'}
],
value='read'
),
html.Br(),
dcc.Input(id='filter-query-input', placeholder='Enter filter query'),
html.Div(id='filter-query-output'),
html.Hr(),
html.Button("Clear Filters", id="clear"),
dash_table.DataTable(
id='datatable-advanced-filtering',
columns=[
{'name': i, 'id': i, 'deletable': True} for i in df.columns
# omit the id column
if i != 'id'
],
data=df.to_dict('records'),
editable=True,
page_action='native',
page_size=10,
filter_action="native"
),
html.Hr(),
html.Div(id='datatable-query-structure', style={'whitespace': 'pre'})
])
@app.callback(
Output('datatable-advanced-filtering', 'filter_query'),
[Input('filter-query-input', 'value'), Input('clear', 'n_clicks')]
)
def write_query(query, clicks):
if clicks != None and clicks > 0:
return ''
else:
if query is None or query == '':
return ''
return query
Any suggestions on how to fix this will be appreciated. Thank you!