Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear all filters in react-table

I am using react-table v7 (https://www.npmjs.com/package/react-table) . I am able to filter the data (referred from https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/filtering ) and I am using SelectColumnFilter function for all the columns to filter . I would like to create a button which will reset all the filters. Like If I have applied filters to 4 columns by clicking on the RESET ALL button I want all the filters to be cleared. Can someone please help me with this ? Thank you

like image 798
Blessy Julie Avatar asked Jan 25 '23 07:01

Blessy Julie


1 Answers

You can get the setAllFilters method from useTable instance, and then

const { ...setAllFilters } = useTable({ columns, data }, userFilters)

// somewhere at you code
<button onClick={() => setAllFilters([])}>Reset</button>

checkout setAllFilters at https://github.com/tannerlinsley/react-table/blob/master/docs/api/useFilters.md

like image 80
goldenbearkin Avatar answered Feb 05 '23 17:02

goldenbearkin