问题
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
回答1:
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
来源:https://stackoverflow.com/questions/60279994/how-to-clear-all-filters-in-react-table