Skip to content
This repository was archived by the owner on Aug 29, 2025. It is now read-only.
This repository was archived by the owner on Aug 29, 2025. It is now read-only.

Clearing filters in filter row of table not working #715

@shwetakinger

Description

@shwetakinger

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.
Screen Shot 2020-03-05 at 6 46 13 PM
After Clicking Clear Filters button - table is no longer filtered, but "eq Afghanistan" remains in column filter in table:
Screen Shot 2020-03-05 at 6 46 28 PM

Here is the code:

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

I have seen the issue : #370. However, this issue pertains to specifically queries entered through an external input. (Clear filters button works fine for clearing filters applied by entering text in filter row of table)
Any suggestions on how to fix this issue will be greatly appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    dash-type-bugSomething isn't working as intended

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions