mirror of
https://github.com/gosticks/react-table.git
synced 2025-10-16 11:55:36 +00:00
- Fixed an issue where dependency hooks were not being reduced properly, thus the table would rerender unnecessarily - Renamed `toggleRowSelectedAll` to `toggleAllRowsSelected`. Duh... - Added an `indeterminate` boolean prop to the default props for row selection toggle prop getters - Renamed `selectedRowPaths` to `selectedRowIds`, which also no longer contains paths, but row IDs - Grouped or nested row selection actions and state are now derived, instead of tracked in state. - Rows now have a new property called `id`, which existed before and was derived from the `getRowId` option - Rows now also have an `isSomeSelected` prop when using the `useRowSelect` hook, which denotes that at least one subRow is selected (if applicable) - Rows' `path` property has been deprecated in favor of `id` - Expanded state is now tracked with row IDs instead of paths - RowState is now tracked with row IDs instead of paths - `toggleExpandedByPath` has been renamed to `toggleExpandedById`, and thus accepts a row ID now, instead of a row path
3.3 KiB
3.3 KiB
useRowState
- Plugin Hook
- Optional
useRowState is a plugin hook that implements basic state management for prepared rows and their cells.
Table Options
The following options are supported via the main options object passed to useTable(options)
state.rowState: Object<RowPathKey:Object<any, cellState: {columnId: Object}>>- Optional
- Defaults to
{} - If a row's ID is found in this array, it will have the state of the value corresponding to that key.
- Individual row states can contain anything, but they also contain a
cellStatekey, which provides cell-level state based on column ID's to every prepared cell in the table.
initialState.rowState- Identical to the
state.rowStateoption above
- Identical to the
initialRowStateAccessor: Function- Optional
- This function may optionally return the initial state for a row.
- If this function is defined, it will be passed a
Rowobject, from which you can return a value to use as the initial state, eg.row => row.original.initialState
autoResetRowState: Boolean- Defaults to
true - When
true, therowStatestate will automatically reset if any of the following conditions are met:datais changed
- To disable, set to
false - For more information see the FAQ "How do I stop my table state from automatically resetting when my data changes?"
- Defaults to
Instance Properties
The following values are provided to the table instance:
setRowState: Function(rowPath: Array<string>, updater: Function | Any) => void- Use this function to programmatically update the state of a row.
updatercan be a function or value. If afunctionis passed, it will receive the current value and expect a new one to be returned.
setCellState: Function(rowPath: Array<string>, columnId: String, updater: Function | Any) => void- Use this function to programmatically update the cell of a row.
updatercan be a function or value. If afunctionis passed, it will receive the current value and expect a new one to be returned.
Row Properties
The following additional properties are available on every prepared row object returned by the table instance.
state: Object- This is the state object for each row, pre-mapped to the row from the table state's
rowStateobject viarowState[row.id] - May also contain a
cellStatekey/value pair, which is used to provide individual cell states to this row's cells
- This is the state object for each row, pre-mapped to the row from the table state's
setState: Function(updater: Function | any)- Use this function to programmatically update the state of a row.
updatercan be a function or value. If afunctionis passed, it will receive the current value and expect a new one to be returned.
Cell Properties
The following additional properties are available on every Cell object returned in an array of cells on every row object.
state: Object- This is the state object for each cell, pre-mapped to the cell from the table state's
rowStateobject viarowState[row.id].cellState[columnId]
- This is the state object for each cell, pre-mapped to the cell from the table state's
setState: Function(updater: Function | any)- Use this function to programmatically update the state of a cell.
updatercan be a function or value. If afunctionis passed, it will receive the current value and expect a new one to be returned.