dash-docs icon indicating copy to clipboard operation
dash-docs copied to clipboard

DataTable filtering: filter_action doesn't work if the columns property is not specified

Open aGitForEveryone opened this issue 4 years ago • 1 comments

For a dashboard I am working on, I have a table in which I assign the columns and data property via a callback. This means that in the layout I just include the data table with an id and some other properties I set. Then I wanted to add filtering to the table and tried adding filter_action='native' to the data table (in the layout). Unfortunately I ran into the error: Cannot read property 'props' of undefined, which came from the underlying Javascript code. So I had no clue where to look to solve it or what was exactly causing it (other than that filter_action was the problem). Long story short after a lot of debugging I found that the problem was that I didn't define the columns property at that time. Apparently filter_action doesn't like that.

Could this dependency be added to the docs page for filtering syntax (or any other page where it would be suitable. I was reading that page). Given the very vague error message, it is hard to debug this issue and there is little to be found on the web to help you.

I was able to solve my issue by adding an output to the callback in which I created the data table columns and data property for the filter_action property. Something like:

@app.callback(
    Output(my_table, columns),
    Output(my_table, data),
    Output(my_table, filter_action),
    Input(my_table_trigger, value)
)
def update_table(update_table):
    if update_table:
        # do something here
        return my_columns, my_data, 'native'

    # return an empty table when the update fails or isn't necessary
    # I didn't know what the default value/None-value was for filter_action (returning None or "" didn't work) 
    # so I invoked dash.no_update which did work.
    return [], [], dash.no_update

aGitForEveryone avatar Sep 14 '21 12:09 aGitForEveryone

I have same bug. Dash_table's filter is not work.

yinssl avatar Apr 18 '23 15:04 yinssl