How to clear all filters in react-table

拟墨画扇 提交于 2020-05-16 02:31:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!