API / Plugins / Base / Selection
SelectionPlugin
The SelectionPlugin from @omnigrid/selection-plugin adds row-selection behavior to the grid. It supports single and multiple modes, optional checkbox columns, per-row selectability, and live change callbacks. Selection state is stored internally and can be queried via the plugin instance methods.
Constructor
new SelectionPlugin<T>(options?: SelectionPluginOptions<T>)Options
Properties accepted by SelectionPluginOptions<T>.
| Property | Description |
|---|---|
mode SelectionModedefault: "single" | Supports selecting one row or multiple rows. |
checkboxOnly booleandefault: false | Restricts selection changes to checkbox interaction. |
replaceSelectionOnClick booleandefault: false | In multiple mode, clicking a row replaces the current selection. |
groupSelection GroupSelectionModedefault: "none" | Enables group checkbox selection in multiple mode. |
showRowCheckboxes booleandefault: false | Adds a checkbox to each row. |
showHeaderCheckbox booleandefault: false | Adds a select-all checkbox to the selection column header. |
selectionColumnId stringdefault: "__omnigrid_selection__" | ID for the automatically inserted checkbox column. |
selectionColumnWidth numberdefault: 36 | Width in pixels of the automatically inserted checkbox column. |
Callbacks
isRowSelectable: (row: T, index: number) => booleanDetermines whether a row can be selected.
checkboxRenderer: SelectionRenderer<T>Renders checkbox UI; defaults to the OmniGrid checkbox renderer.
onSelectionChange: (state: SelectionState<T>) => voidCalled when the selected rows change.
Instance methods
getSelectedRowIds(): RowId[]Returns the IDs of all currently selected rows.
getSelectedRows(): T[]Returns the data objects of all currently selected rows.
getSelectionState(): SelectionState<T>Returns selected row IDs and row data together.
isSelected(rowId): booleanChecks whether a row ID is currently selected.
setSelectedRowIds(rowIds): voidReplaces the current selection with the supplied row IDs.
clearSelection(): voidClears all selected rows.
toggleRow(rowId, index, modifiers?): voidToggles a row's selection. Shift and Ctrl modifiers control range and additive selection.
updateOptions(newOptions): voidUpdates plugin options at runtime.
Types and Interfaces
SelectionModeSelection behavior supported by the plugin.
type SelectionMode = "single" | "multiple";GroupSelectionModeControls whether group checkboxes select their descendants.
type GroupSelectionMode = "none" | "descendants" | "filteredDescendants";SelectionRendererParamsValues provided to a custom checkbox renderer.
interface SelectionRendererParams<T> extends CheckboxRenderParams {
/** Row data for a row checkbox; absent for the header checkbox. */
data?: T;
/** Row identifier for a row checkbox. */
rowId?: RowId;
/** Row index for a row checkbox. */
index?: number;
/** Whether the renderer is being called for the header checkbox. */
header: boolean;
/** Whether the row checkbox represents a composite row. */
group?: boolean;
}SelectionRendererRenderer used to customize selection checkboxes.
type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;SelectionStateSelected row identifiers and their corresponding row data.
interface SelectionState<T> {
/** IDs of selected rows. */
selectedRowIds: RowId[];
/** Data objects for selected rows. */
selectedRows: T[];
}