javascript - 如何防止 react 表排序和搜索重置

标签 javascript reactjs react-table-v7

在这个官方示例中,表格排序和搜索会在任何可编辑字段模糊时重置。 https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/kitchen-sink?file=/src/App.js
我怎样才能防止这种情况发生?我希望排序和搜索保持不变,即使有人编辑了数据。

最佳答案

使用 sortBy 时,您可以将此属性设置为 false

autoResetSortBy: Boolean

  • Defaults to true
  • When true, the sortBy state will automatically reset if any of the following conditions are met: data is changed
  • To disable, set to false

https://react-table.tanstack.com/docs/api/useSortBy

过滤也是一样

autoResetFilters: Boolean

  • Defaults to true
  • When true, the filters state will automatically reset if any of the following conditions are met: data is changed
  • To disable, set to false

https://react-table.tanstack.com/docs/api/useFilters

另请参阅此常见问题解答 https://react-table.tanstack.com/docs/faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes

编辑 为了完整起见,还可以在全局过滤器上设置 autoResetGlobalFilter:see documentation .

关于javascript - 如何防止 react 表排序和搜索重置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62450548/

相关文章:

javascript - 两个日期时间字符串有什么区别?

javascript - Jest Enzyme 如何对包装组件的存在进行浅层测试

javascript - HighCharts - 在缩放重置中设置最大值和最小值

javascript - 在javascript中转换每个数组值ias对象不起作用

Javascript jquery - 如何在搜索条目中建立延迟

javascript - 在 React Native 中将参数传递给组件

reactjs - React 测试库 - 无法测试窗口调整 React Hook

reactjs - 使用自定义字段而不是索引来 react 表行选择

reactjs - react : declaration merging for react-table types doesn't work. 类型 'TableInstance' 上不存在属性