useTableColumnResizeState
Provides column width state management for a table component with column resizing support. Handles building a map of column widths calculated from the table's width and any provided column width information from the collection. In addition, it tracks the the currently resizing column and provides callback for updating the widths upon resize operations.
| install | yarn add react-stately |
|---|---|
| version | 3.20.0 |
| usage | import {useTableColumnResizeState} from 'react-stately' |
API#
useTableColumnResizeState<T>(
(props: TableColumnResizeStateProps<T>,
, state: TableState<T>
)): TableColumnResizeState<T>
Interface#
| Name | Type | Description |
onColumnResize | (
(key: Key,
, width: number
)) => Map<Key, ColumnSize> | Called to update the state that a resize event has occurred. Returns the new widths for all columns based on the resized column. * |
onColumnResizeStart | (
(key: Key
)) => void | Callback for when onColumnResize has started. |
onColumnResizeEnd | () => 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. |
widths | Map<Key, number> | Currently calculated widths for all columns. |
resizingColumn | Key | null | Key of the currently resizing column. |
tableState | TableState<T> | A reference to the table state. |
Example#
// TODO: link to the resizing section specifically
See the docs for useTable in react-aria for an example of using useTableColumnResizeState
with useTableState to create a table with resizable columns.