React-table: How the best way to clear all filters?

Created on 11 Oct 2017  路  3Comments  路  Source: tannerlinsley/react-table

What version of React-Table are you using?

V 6.5.3

What bug are you experiencing, or what feature are you proposing?

I'm using tableRef.filterColumn method fired by redux actions from external components.
For each column I have custom methods that's handling the filter and is working well, the problem is when I try to clean all filtered columns in one action.
I've tried table.setState({filtered:[]}) also map all filtered columns calling filterColumn like this filteredColumns.map((column) => table.filterColumn(table.props.columns[column], ''));
none of them works is there a better way to handle external custom filters?

I'm avoiding filtering the data manually since the component provides the feature, but before doing this last try I'd like to know if there is a better way to force the component re-rendering

Use https://codesandbox.io/s/X6npLXPRW (by clicking the "Fork" button) to reproduce the issue.

This is a similar example of what I'm trying to archive using both ideas I explained, although I'm using external component dispatching redux action and using sagas to handle the side effects.

https://codesandbox.io/s/n055o7z40l

The problem with the loop solution is that sometimes it works sometime it clears just one of them.

Probably there is a better way to implement custom filters from external components, just couldn't figure it out.

Thanks for helping!

All 3 comments

I think you are probably better off pushing this onto the Slack #react-table channel. However, the easiest way to set a filter is to use the filtered prop. If you set the conditions that way and pass it in, then you only need to set it to an empty array to clear it.

Thanks @gary-menzel I've tried to find the slack chat I saw in a post on Medium but was a broken link so I though you guys had closed it. Now I found the right one.
I'm gonna ask people there.

Cheers!

this is the solution

https://codesandbox.io/s/v6n31p1kl

Was this page helpful?
0 / 5 - 0 ratings

Related issues

williamolojede picture williamolojede  路  3Comments

mlajszczak picture mlajszczak  路  3Comments

mellis481 picture mellis481  路  3Comments

monarajhans picture monarajhans  路  3Comments

panfiva picture panfiva  路  3Comments