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.

Live demo|NPM

Constructor

new SelectionPlugin<T>(options?: SelectionPluginOptions<T>)

Options

Properties accepted by SelectionPluginOptions<T>.

PropertyDescription

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) => boolean

Determines whether a row can be selected.

checkboxRenderer: SelectionRenderer<T>

Renders checkbox UI; defaults to the OmniGrid checkbox renderer.

onSelectionChange: (state: SelectionState<T>) => void

Called 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): boolean

Checks whether a row ID is currently selected.

setSelectedRowIds(rowIds): void

Replaces the current selection with the supplied row IDs.

clearSelection(): void

Clears all selected rows.

toggleRow(rowId, index, modifiers?): void

Toggles a row's selection. Shift and Ctrl modifiers control range and additive selection.

updateOptions(newOptions): void

Updates plugin options at runtime.

Types and Interfaces

SelectionMode

Selection behavior supported by the plugin.

type SelectionMode = "single" | "multiple";
GroupSelectionMode

Controls whether group checkboxes select their descendants.

type GroupSelectionMode = "none" | "descendants" | "filteredDescendants";
SelectionRendererParams

Values 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;
}
SelectionRenderer

Renderer used to customize selection checkboxes.

type SelectionRenderer<T> = (params: SelectionRendererParams<T>) => unknown;
SelectionState

Selected row identifiers and their corresponding row data.

interface SelectionState<T> {
    /** IDs of selected rows. */
    selectedRowIds: RowId[];
    /** Data objects for selected rows. */
    selectedRows: T[];
}