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

Clearing filtering_settings does not clear the by-column filter fields #370

Closed
Marc-Andre-Rivet opened this issue Feb 12, 2019 · 7 comments
Labels
dash-type-bug Something isn't working as intended

Comments

@Marc-Andre-Rivet
Copy link
Contributor

From community thread.

Clearing the filtering_settings does not cause the by-column filter fields to be cleared. The table displays the right data but the fields themselves are showing the previous value.

Expected resolution:

  • fixes the behavior
  • adds at least one test demonstrating that resetting the filtering_settings prop causes the filter fields to be cleared in the UI

community-19381

import pandas as pd
import numpy as np

from datetime import date

import dash
from dash.dependencies import Input, Output, State
import dash_html_components as html
from dash_table import DataTable

app = dash.Dash(__name__)
app.css.config.serve_locally = True
app.scripts.config.serve_locally = True

sColNames = ['a' + str(x) for x in range(date.today().year-6, date.today().year+1)]
df =  pd.DataFrame(data = np.array([[1.5,0.0,-1.5]]*7).T, index=range(3), columns=sColNames) # Example dataframe

app.layout = html.Div(children=[
    html.Button(id='clear', children='Clear filter'),
    DataTable(
        id='table',
        columns=[{'name': i, 'id': i} for i in df.columns],
        data=df.to_dict('rows'),
        filtering=True
    )
])

@app.callback(
    Output('table', 'filtering_settings'),
    [Input('clear', 'n_clicks')],
    [State('table', 'filtering_settings')],
)
def clearFilter(n_clicks, state):
    if n_clicks is None:
        return '' if state is None else state

    return ''


if __name__ == "__main__":
    app.run_server(debug=True)
@Marc-Andre-Rivet Marc-Andre-Rivet added dash-type-bug Something isn't working as intended Attribute: Functionality labels Feb 12, 2019
@Marc-Andre-Rivet Marc-Andre-Rivet changed the title Clearing filtering_settings does not clear the filter fields Clearing filtering_settings does not clear the by-column filter fields Feb 12, 2019
@evanfrisch
Copy link

Great! Thanks.

@ibusko
Copy link

ibusko commented Oct 15, 2020

I have dash 1.11.0. The bug seems to be present still. The clearing action doesn't do anything in my code.

When I try to run the example above, I get an error saying that 'filtering_settings' is not supported by DataTable.

I wonder if other developments happened in the meantime and now the method to clear filters changed?

@a69e
Copy link

a69e commented Mar 8, 2021

I have dash 1.11.0. The bug seems to be present still. The clearing action doesn't do anything in my code.

When I try to run the example above, I get an error saying that 'filtering_settings' is not supported by DataTable.

I wonder if other developments happened in the meantime and now the method to clear filters changed?

Try install newer version(dash 1.19.0 and dash-table 4.11.2)

@a69e
Copy link

a69e commented Mar 8, 2021

@Marc-Andre-Rivet There's no such argument "filtering=True" for DataTable, and if I input that it will get an unexpected keyword argument error and if I don't input, the clear filter won't work at all.

@cobujo
Copy link

cobujo commented Apr 13, 2021

Not sure if this will catch any eyeballs since it's closed, but I'm still seeing an issue here . . .

I have some custom buttons and callbacks that load a saved "view" which includes visible and ordered columns, filter_query and sort_by. If I'm using the filter query input in the UI I don't see any residual text in the input field BUT when switching views from a view with filters to a view with no filters, the filter is correctly executed in the table but I still see the input "ghost" text from the previous view.

I have a datatable with an update interval component, and the ghost text appears to show back up on the interval when data is updated. What's even stranger is, I setup a clientside callback with Inputs: interval update and filter_query, which sets the value of the filter query input element to "" when the filter query is currently blank or None, and the ghost text still shows up after flashing blank for a moment.

Is this some side effect of React thinking that the component state needs to be restored (since my clientside callback is technically changing the DOM)? I have a feeling about this but I also don't see any output about this in the devtools console.

@szkjn
Copy link

szkjn commented Feb 18, 2022

It looks like filtering_settings needs to be replace by filter_guery in the callback, like so :

@app.callback(
    Output('table', 'filter_query'),
    [Input('clear', 'n_clicks')],
    [State('table', 'filter_query')],
)
def clearFilter(n_clicks, state):
    if n_clicks is None:
        return '' if state is None else state
    return ''

Just spent an hour reading all the threads on this matter and this is working for me.

No mention of filtering_settings in the official documentation, plus #169 opens a discussion about "the next version of the filtering_settings property. In particular : its name".

So I'm assuming filter_query is the new property name.

Do correct me if I'm wrong !

@alexcjohnson
Copy link
Collaborator

Yes, filter_query. Please note the table API changed substantially with Dash 1.0 https://dash.plotly.com/dash-1-0-migration#dash_table and then as of last summer with Dash 2.0 this repo is no longer in use - dash-table is now part of the main repo https://github.com/plotly/dash

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

7 participants