question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Clearing `filtering_settings` does not clear the by-column filter fields

See original GitHub issue

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)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
szkjncommented, 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 !

0reactions
alexcjohnsoncommented, Feb 18, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Clear or remove a filter - Microsoft Support
Remove filters from columns so you can view more or all of your data. ... button next to the column heading, and then...
Read more >
Clearing Only Filtering Settings - Excel Ribbon Tips
On the Data tab of the ribbon, in the Sort & Filter group, there is a Clear tool. This tool clears all filtering...
Read more >
How to Clear or Remove Filter in Excel - YouTube
In the previous tutorial you could see how to create a filter in Excel. Today, we'll have a look at how to clear...
Read more >
Clear All Filter Criteria is not clearing all FilterConditions
I tested “clearing filter conditions” functionality in 14.2 and it is working as expected. AfterRowFilterChanged event is called for each column ...
Read more >
DataTable clearFilter() not working properly - Stack Overflow
To clear all the inputs of the filters you can do it by javascript: <p:commandButton onclick="PF('vtWidget').clearFilters()" />.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found