Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prevent react-table sort and search reset

In this official example, table sorting and searching resets on blur of any editable field.https://codesandbox.io/s/github/tannerlinsley/react-table/tree/master/examples/kitchen-sink?file=/src/App.js
How can I prevent that? I want sort and search to stay the same, even if someone edits the data.

like image 874
Asela Avatar asked Mar 16 '26 00:03

Asela


1 Answers

When using sortBy you can set this property to 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

The same thing for filtering

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

Also see this FAQ https://react-table.tanstack.com/docs/faq#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes

Edit For completeness, one can also set autoResetGlobalFilter on the global filter: see documentation.

like image 125
John Ashmore Avatar answered Mar 17 '26 14:03

John Ashmore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!