Skip to content

Commit c8ca46e

Browse files
committed
docs(AnalyticalTable): explain how to prevent table resets after data has changed
[ci skip] Closes #557
1 parent 6e59955 commit c8ca46e

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

packages/main/src/components/AnalyticalTable/AnalyticalTable.mdx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,44 @@ import { Story, Props, Title, Subtitle, Description, Primary, Stories } from '@s
3838
|`hAlign` | `TextAlign` |Horizontal align of the cell|
3939
|`vAlign` | `VerticalAlign` |Vertical align of the cell|
4040

41+
## Recipes
42+
43+
### How do I stop my table state from automatically resetting when my data changes?
44+
45+
46+
By default, the `AnalyticalTable` will reset the sorters, filters, grouping, selected rows, etc. when the table data changes.
47+
In case you want to keep the current state of the Table, you can disable this behavior by using the `reactTableOptions` prop:
48+
```jsx
49+
const [data, setData] = React.useState([])
50+
const skipPageResetRef = React.useRef()
51+
52+
const updateData = newData => {
53+
// When data gets updated with this function, set a flag
54+
// to disable all of the auto resetting
55+
skipPageResetRef.current = true
56+
57+
setData(newData)
58+
}
59+
60+
React.useEffect(() => {
61+
// After the table has updated, always remove the flag
62+
skipPageResetRef.current = false
63+
})
64+
<AnalyticalTable
65+
columns={columns}
66+
data={data}
67+
reactTableOptions={{
68+
// ... any other options you want to set
69+
autoResetExpanded: !skipPageResetRef.current,
70+
autoResetGroupBy: !skipPageResetRef.current,
71+
autoResetSelectedRows: !skipPageResetRef.current,
72+
autoResetSortBy: !skipPageResetRef.current,
73+
autoResetFilters: !skipPageResetRef.current,
74+
}}
75+
/>
76+
```
77+
78+
For more details on this behavior you can double check the [react-table docs](https://github.com/tannerlinsley/react-table/blob/master/docs/faq.md#how-do-i-stop-my-table-state-from-automatically-resetting-when-my-data-changes).
79+
4180
<Stories />
4281

0 commit comments

Comments
 (0)