useTableState
Provides state management for a table component. Handles building a collection of columns and rows from props. In addition, it tracks row selection and manages sort order changes.
install | yarn add react-stately |
---|---|
version | 3.35.0 |
usage | import {useTableState, useTableColumnResizeState} from 'react-stately' |
API#
useTableState<T extends object>(
(props: <T>
)): <T>
useTableColumnResizeState<T>(
(props: <T>,
, state: <T>
)): <T>
Cell(
(props:
)): ReactElement | null
Column<T>(
(props: <T>
)): ReactElement | null
Row<T>(
(props: <T>
)): ReactElement | null
TableBody<T>(
(props: <T>
)): ReactElement | null
TableHeader<T>(
(props: <T>
)): ReactElement | null
Interface#
useTableState#
Properties
Name | Type | Description |
collection | <T> | A collection of rows and columns in the table. |
showSelectionCheckboxes | boolean | Whether the row selection checkboxes should be displayed. |
sortDescriptor | | null | The current sorted column and direction. |
isKeyboardNavigationDisabled | boolean | Whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. |
setKeyboardNavigationDisabled | (
(val: boolean
)) => void | Set whether keyboard navigation is disabled, such as when the arrow keys should be handled by a component within a cell. |
disabledKeys | Set<Key> | A set of keys for rows that are disabled. |
selectionManager |
| A selection manager to read and update row selection state. |
Methods
Method | Description |
sort(
(columnKey: Key,
, direction?: 'ascending'
| | 'descending'
)): void | Calls the provided onSortChange handler with the provided column key and sort direction. |
useTableColumnResizeState#
Name | Type | Description |
updateResizedColumns | (
(key: Key,
, width: number
)) => Map<Key, > | Called to update the state that a resize event has occurred. Returns the new widths for all columns based on the resized column. |
startResize | (
(key: Key
)) => void | Callback for when onColumnResize has started. |
endResize | () => void | Callback for when onColumnResize has ended. |
getColumnWidth | (
(key: Key
)) => number | Gets the current width for the specified column. |
getColumnMinWidth | (
(key: Key
)) => number | Gets the current minWidth for the specified column. |
getColumnMaxWidth | (
(key: Key
)) => number | Gets the current maxWidth for the specified column. |
resizingColumn | Key | null | Key of the currently resizing column. |
tableState | <T> | A reference to the table state. |
columnWidths | Map<Key, number> | A map of the current column widths. |
Example#
See the docs for useTable in react-aria for an example of useTableState
, useTableColumnResizeState
, Cell
, Column
,
Row
, TableBody
, and TableHeader
.