You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/main/src/components/AnalyticalTable/docs/FAQ.mdx
+42-13Lines changed: 42 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -158,42 +158,71 @@ For other elements or components, we recommend either disabling event propagatio
158
158
159
159
## How to stop the table state from automatically resetting when the data changes?
160
160
161
-
By default, the `AnalyticalTable` will reset the sorters, filters, grouping, selected rows, etc. when the table data changes. It will also reset all manually resized columns if the container width changes.
162
-
In case you want to keep the current state of the Table, you can disable this behavior by using the `reactTableOptions` prop or for column resize the `retainColumnWidth` prop.
161
+
By default, the `AnalyticalTable` resets most table state whenever the `data` or `columns` reference changes.
162
+
163
+
### What resets when?
164
+
165
+
Each `autoReset*` option defaults to `true`. Most trigger on **`data`** changes, but `autoResetResize` is the exception - it triggers on **`columns`** changes.
166
+
167
+
<details>
168
+
<summary>Full list of <code>autoReset*</code> options</summary>
169
+
170
+
|`reactTableOptions` option | Default | Resets on | What it resets |
**Important:** Column resize widths are never reset by `data` changes - only by `columns` changes. If you want to preserve user-resized widths across column changes, set `autoResetResize: false`.
184
+
185
+
### `retainColumnWidth` prop
186
+
187
+
`retainColumnWidth` is a separate mechanism from `autoResetResize`. It controls what happens on **container resizes** (e.g., window resize):
188
+
189
+
-**Without**`retainColumnWidth`: A container resize clears user-resized column widths and triggers dynamic width recalculation.
190
+
-**With**`retainColumnWidth`: User-resized column widths are preserved across container resizes.
191
+
192
+
### Keeping state across data updates
193
+
194
+
To prevent automatic resets when updating data, set the corresponding `autoReset*` option to `false` in `reactTableOptions`. The ref-based flag shown below is optional - it avoids an unnecessary re-render by reading the flag during render instead of toggling state:
163
195
164
196
```jsx
165
-
const [data, setData] =React.useState([])
166
-
constskipPageResetRef=React.useRef(false)
197
+
const [data, setData] =useState([])
198
+
constskipPageResetRef=useRef(false)
167
199
168
200
constupdateData=newData=> {
169
-
// When data gets updated with this function, set a flag
170
-
// to disable all of the auto resetting
201
+
// When data gets updated with this function, set a flag to disable all of the auto resetting
171
202
skipPageResetRef.current=true
172
203
173
204
setData(newData)
174
205
}
175
206
176
-
React.useEffect(() => {
177
-
// After the table has updated, always remove the flag
207
+
useEffect(() => {
208
+
// After the table has updated, remove the flag
178
209
skipPageResetRef.current=false
179
210
})
180
211
<AnalyticalTable
181
212
columns={columns}
182
213
data={data}
183
-
//disable auto reset of columns width if a column has been manually resized
214
+
//preserve user-resized widths across container resizes
0 commit comments