Skip to content

SelectionMethods

Selection methods returned from injectGridSelection.

Uses lazy discovery - the grid is found on first method call, not during initialization. This ensures it works with lazy-rendered tabs, conditional rendering, etc.

PropertyTypeDescription
selectAll() => voidSelect all rows (row mode) or all cells (range mode).
clearSelection() => voidClear all selection.
getSelection() => SelectionResult | unknownGet the current selection state (imperative, point-in-time snapshot). For reactive selection state, use the selection signal instead.
isCellSelected(row: number, col: number) => booleanCheck if a specific cell is selected.
setRanges(ranges: CellRange[]) => voidSet selection ranges programmatically.
selectionSignal<SelectionResult | unknown>Reactive selection state. Updates automatically whenever the selection changes. Null when no SelectionPlugin is active or no selection has been made yet.
selectedRowIndicesSignal<number[]>Reactive selected row indices (sorted ascending). Updates automatically. Convenience signal for row-mode selection — returns [] in cell/range modes or when nothing is selected.
selectedRowsSignal<TRow[]>Reactive selected row objects. Updates automatically whenever the selection changes. Works in all selection modes (row, cell, range) — returns the actual row objects from the grid’s processed (sorted/filtered) rows.
isReadySignal<boolean>Signal indicating if grid is ready. The grid is discovered lazily, so this updates when first method call succeeds.
readonly selection = injectGridSelection();
// In template:
// {{ selection.selection()?.ranges?.length ?? 0 }} cells selected
// In computed:
readonly hasSelection = computed(() => (this.selection.selection()?.ranges?.length ?? 0) > 0);

Reactive selected row indices (sorted ascending). Updates automatically. Convenience signal for row-mode selection — returns [] in cell/range modes or when nothing is selected.

Prefer selectedRows for getting actual row objects — it handles index-to-object resolution correctly regardless of sorting/filtering.

readonly selection = injectGridSelection();
// In template:
// {{ selection.selectedRowIndices().length }} rows selected

Reactive selected row objects. Updates automatically whenever the selection changes. Works in all selection modes (row, cell, range) — returns the actual row objects from the grid’s processed (sorted/filtered) rows.

This is the recommended way to get selected rows. Unlike manual index mapping, it correctly resolves rows even when the grid is sorted or filtered.

readonly selection = injectGridSelection<Employee>();
// In template:
// {{ selection.selectedRows().length }} rows selected
// In computed:
readonly hasSelection = computed(() => this.selection.selectedRows().length > 0);

AI assistants: For complete API documentation, implementation guides, and code examples for this library, see https://raw.githubusercontent.com/OysteinAmundsen/toolbox/main/llms-full.txt