Skip to content

useTableSelection

@astryxdesign/core v0.7.1 · useTableSelection

The config is a MaybeRefOrGetter, so pass a getter or a ref to keep the plugin on the current values.

Parameters ​

NameTypeDefaultDescription
getIsItemSelected(item: T) => boolean—Returns whether the given item is currently selected.
onSelectItem(event: { item: T; isSelected: boolean }) => void—Called when a row checkbox is toggled. isSelected is the new desired state.
onSelectAll(event: { isAllSelected: boolean }) => void—Called when the select-all header checkbox is toggled.
getIsAllSelected() => boolean—Returns whether all selectable items are currently selected.
getIsIndeterminate() => boolean() => falseReturns whether selection is partial (some but not all). Renders the select-all checkbox in indeterminate state.
getIsItemSelectable(item: T) => boolean() => trueReturns whether a row should show a checkbox. Non-selectable rows render nothing in the selection cell.
getIsItemEnabled(item: T) => boolean() => trueReturns whether a row checkbox is interactive. Disabled rows keep their checkbox, rendered disabled, so the selection column stays aligned.
getRowLabel(item: T) => string—Derives a human-readable identity for a row; the row checkbox's hidden label becomes Select ${getRowLabel(item)} so screen readers announce which row each checkbox selects. Falls back to "Select row" when omitted.
hasRowHighlightbooleantruePaints checked rows with the accent wash. Set false when the surrounding UI already uses row background to mean something else (a row open in a detail panel, say). Only the background is dropped: aria-selected is still set on checked rows either way.

Returns ​

FieldTypeDescription
selectionTableSelectionContribution<T>The plugin contribution the table reads. Put the whole plugin under any key of the plugins prop; the table picks up the one entry that has selection.
selection.isAllSelected() => booleanWraps getIsAllSelected.
selection.isIndeterminate() => booleanWraps getIsIndeterminate, or false when it is omitted.
selection.isSelected(row: T) => booleanWraps getIsItemSelected.
selection.isSelectable(row: T) => booleanWraps getIsItemSelectable, or true when it is omitted.
selection.isEnabled(row: T) => booleanWraps getIsItemEnabled, or true when it is omitted.
selection.selectAll(selected: boolean) => voidCalls onSelectAll with { isAllSelected: selected }.
selection.selectRow(row: T, selected: boolean) => voidCalls onSelectItem with { item: row, isSelected: selected }.
selection.rowLabel(row: T) => stringWraps getRowLabel, or an empty string when it is omitted.
selection.hasRowHighlightboolean | undefinedThe value from the config. Anything other than false keeps the wash.