Skip to content
This repository was archived by the owner on Jun 4, 2024. It is now read-only.

Clearing filters in filter row of table not working #715

Open
shwetakinger opened this issue Mar 6, 2020 · 5 comments
Open

Clearing filters in filter row of table not working #715

shwetakinger opened this issue Mar 6, 2020 · 5 comments
Labels
dash-type-bug Something isn't working as intended
Milestone

Comments

@shwetakinger
Copy link

shwetakinger commented Mar 6, 2020

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.

@Marc-Andre-Rivet
Copy link
Contributor

Looks like the issue is specific to clearing / emptying the filter. Changing the filter for another valid / not empty one updates correctly.

@Marc-Andre-Rivet Marc-Andre-Rivet added the dash-type-bug Something isn't working as intended label Apr 2, 2020
@Marc-Andre-Rivet Marc-Andre-Rivet added this to the Dash v1.x milestone Apr 2, 2020
@amitsh1
Copy link

amitsh1 commented Jun 25, 2020

workaround:
if you have a column that is not necessary for filtering you can use it to clear all columns by hiding it and then filling it with a valid, non filtering filter (such as {MAPS} !="some impossible value")

css:
th.dash-filter.column-1.last-of-type[data-dash-column="MAPS"] > input[type=text] {
display: none;

}

th.dash-filter.column-1[data-dash-column="MAPS"] > input[type=text] {
display: none;

}

@NonStopAggroPop
Copy link

Hi, is there an update to this issue?

Or at least I would appreciate additional input on the workaround. I have tried to put a dummy_column in "hidden_columns" when setting up the table. But then, in the callback I cannot set the filter query for "{hidden_column} != IMPOSSIBLE_VALUE", since for dash this column does not exist.

And for @amitsh1 suggestion, I was not able to hide the column via css (which I admit, never really was comfortable dealing with). Do I just put those two commands into the base-styles.css? And what does the th in the beginng stand for?
Thanks a lot for the help!

@jborman-exos
Copy link

@NonStopAggroPop this dash-table repo is unmaintained. I've opened an issue in the new repo here

@mz09code
Copy link

mz09code commented Sep 3, 2022

Hey, i had the same issues and i found this:
#370 (comment).
It works for me. Help it's helpful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dash-type-bug Something isn't working as intended
Projects
None yet
Development

No branches or pull requests

6 participants