Row selection state is stored on the table using the following shape:
export type RowSelectionState = Record<string, boolean>
export type RowSelectionTableState = { rowSelection: RowSelectionState}
By default, the row selection state uses the index of each row as the row identifiers. Row selection state can instead be tracked with a custom unique row id by passing in a custom getRowId function to the the table.
enableRowSelection
enableRowSelection?: boolean | ((row: Row<TData>) => boolean)
enableMultiRowSelection
enableMultiRowSelection?: boolean | ((row: Row<TData>) => boolean)
enableSubRowSelection
enableSubRowSelection?: boolean | ((row: Row<TData>) => boolean)
Enables/disables automatic sub-row selection when a parent row is selected, or a function that enables/disables automatic sub-row selection for each row.
(Use in combination with expanding or grouping features)
onRowSelectionChange
onRowSelectionChange?: OnChangeFn<RowSelectionState>
If provided, this function will be called with an updaterFn
when state.rowSelection
changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
getToggleAllRowsSelectedHandler
getToggleAllRowsSelectedHandler: () => (event: unknown) => void
Returns a handler that can be used to toggle all rows in the table.
getToggleAllPageRowsSelectedHandler
getToggleAllPageRowsSelectedHandler: () => (event: unknown) => void
Returns a handler that can be used to toggle all rows on the current page.
setRowSelection
setRowSelection: (updater: Updater<RowSelectionState>) => void
Sets or updates the state.rowSelection
state.
resetRowSelection
resetRowSelection: (defaultState?: boolean) => void
Resets the rowSelection state to the initialState.rowSelection
, or true
can be passed to force a default blank state reset to {}
.
getIsAllRowsSelected
getIsAllRowsSelected: () => boolean
Returns whether or not all rows in the table are selected.
getIsAllPageRowsSelected
getIsAllPageRowsSelected: () => boolean
Returns whether or not all rows on the current page are selected.
getIsSomeRowsSelected
getIsSomeRowsSelected: () => boolean
Returns whether or not any rows in the table are selected.
NOTE: Returns false
if all rows are selected.
getIsSomePageRowsSelected
getIsSomePageRowsSelected: () => boolean
Returns whether or not any rows on the current page are selected.
toggleAllRowsSelected
toggleAllRowsSelected: (value: boolean) => void
Selects/deselects all rows in the table.
toggleAllPageRowsSelected
toggleAllPageRowsSelected: (value: boolean) => void
Selects/deselects all rows on the current page.
getPreSelectedRowModel
getPreSelectedRowModel: () => RowModel<TData>
getSelectedRowModel
getSelectedRowModel: () => RowModel<TData>
getFilteredSelectedRowModel
getFilteredSelectedRowModel: () => RowModel<TData>
getGroupedSelectedRowModel
getGroupedSelectedRowModel: () => RowModel<TData>
getIsSelected
getIsSelected: () => boolean
Returns whether or not the row is selected.
getIsSomeSelected
getIsSomeSelected: () => boolean
Returns whether or not some of the row's sub rows are selected.
getIsAllSubRowsSelected
getIsAllSubRowsSelected: () => boolean
Returns whether or not all of the row's sub rows are selected.
getCanSelect
getCanSelect: () => boolean
Returns whether or not the row can be selected.
getCanMultiSelect
getCanMultiSelect: () => boolean
Returns whether or not the row can multi-select.
getCanSelectSubRows
getCanSelectSubRows: () => boolean
Returns whether or not the row can select sub rows automatically when the parent row is selected.
toggleSelected
toggleSelected: (value?: boolean) => void
Selects/deselects the row.
getToggleSelectedHandler
getToggleSelectedHandler: () => (event: unknown) => void
Returns a handler that can be used to toggle the row.
Your weekly dose of JavaScript news. Delivered every Monday to over 100,000 devs, for free.