SelectionModel is a class that manages the various modes and types of selections within a grid. It supports basic modes like single cell, row, column, and range selections, as well as advanced mode like negative ranges. Events related to selections, such as changes to a selection, are propagated to listeners through the EventSelectionChangedListener interface.

The class extends SelectionModelIf interface and defines additional methods and fields specific to its functionality.

Method

constructor(selectionType?: ExtendedSelectionType, selectionMode?: SelectionMode) - Constructs a new instance of the SelectionModel class.

Method

getEventSelectionChangedListeners(): EventSelectionChangedListenerIf[] - Returns the array of registered event selection changed listeners.

Method

addEventSelectionChangedListener(listener: EventSelectionChangedListenerIf): void - Adds an event selection changed listener to the array.

Method

removeEventSelectionChangedListener(listener: EventSelectionChangedListenerIf): void - Removes a specific event selection changed listener if it exists.

Method

fireChangeEvent(): void - Fires a change event on each registered listener when a selection change occurs. Does nothing if the silent property is true.

Method

firstClick(rowIndex: number, columnIndex: number): void - Initiates a selection operation at the specified coordinates. The nature of the operation is determined by the current selection type and mode.

Method

getSelectionCount(rowIndex: number, columnIndex: number): number - Returns the selection count of current ranges

Method

isInNegativeRange(rowIndex: number, columnIndex: number): boolean - Verifies if any point (cell) is in negative range or not.

Method

getRanges() - Returns the selection ranges

Method

clear(): void - Clears all selections in all ranges and resets allSelected and negativeRanges arrays.

Method

hasSelection(): boolean - Checks whether there is any selection. Returns true if yes, false if no.

Method

hasNoSelection(): boolean - Checks whether there is no selection. Returns true if yes, false if no.

Method

getMergedRowIndices(rowCount?: number): number[] - Gets the sorted indices of all rows with at least one selected cell.

Method

selectAll(): void - Selects all selectable entities (also cells that were deselected before). No-op for type "none".

Method

isAllSelected() - Checks if all selectable entities are selected.

Method

addSelection(range: CellRange): void - Adds a certain range to the selection (selects removed cells again).

Method

removeSelection(range: CellRange): void - Removes a certain range from the selection.

Method

togglePoint(row: number, col: number): void - Toggles the selection state of a point at the specified row and column in a grid.

Method

isSelected(row: number, col: number): boolean - Checks if a specific cell in a grid is selected.

Method

addRange(range: CellRange): void - Adds a range of cells to the selection.

Hierarchy

Implements

Constructors

Properties

allSelected: boolean = false

This is a flag to indicate whether all cells in the grid are selected or not.

negativeRanges: CellRange[] = []

This contains all the current negative cell ranges in the grid.

ranges: CellRange[] = []

This contains all the current selected cell ranges in the grid.

selectionMode: SelectionMode = "single"

The mode of selection being used. It's of type SelectionMode. Default: "single"

selectionType: ExtendedSelectionType = "none"

The type of selection being used. It's of type ExtendedSelectionType. Default: "none"

silent: boolean = false

This is a flag to suppress the firing of selection change events.

Methods

  • Adds a rectangle to the selection (adjusted to the selection type: whole rows for "row", whole columns for "column", the first cell for "cell"). Cells of the rectangle that were deselected before (removeSelection) are selected again – the last operation wins.

    Parameters

    • range: CellRange

      the cells to select (adjusted in place to the selection type)

    Returns void

  • The indices of all rows that contain at least one selected cell, sorted ascending and without duplicates. A row whose selected cells were all removed again (removeSelection) is left out.

    Ranges that cover all rows (selection type "column", CellRange.singleColumn: r2 = Number.MAX_SAFE_INTEGER) and selectAll can only be resolved with rowCount. Without it they are skipped (before, such a range made this method loop forever) – pass the number of (displayed) body rows to get them, too.

    Parameters

    • Optional rowCount: number

      number of body rows; rows >= rowCount are left out, and "all rows" (column ranges, selectAll) becomes 0 … rowCount - 1

    Returns number[]

    row indices, sorted ascending

    Example

    const rowCount = tableModel.getBodyModel().getRowCount();
    const rowIndices = selectionModel.getMergedRowIndices(rowCount); // e.g. [1, 2, 5]
    console.log(`${rowIndices.length} rows with selected cells`);
  • Removes the cells of range from all negative ranges ("last operation wins": cells added after they were removed are selected again). A negative range that overlaps range is split into up to four rectangles (above, below, left and right of the overlap); unbounded ranges (Number.MAX_SAFE_INTEGER) work as well.

    Parameters

    • range: CellRange

      the cells that are selected again

    Returns void

  • Selects a deselected cell again ("toggle on") by lifting the negative ranges at this cell (for selection type "row"/"column": at its whole row/column) – only possible while the cell is still inside a selected range or everything is selected. Fires no event.

    Parameters

    • row: number

      row index

    • col: number

      column index

    Returns boolean

    true if the cell is selected again, false if it has to be added as a new range

  • Toggles the selection state of a cell (for selection type "row"/"column": of its row/column). A cell that was deselected inside a selected range (or after selectAll) gets selected again without adding a second, overlapping range.

    Parameters

    • row: number

      row index

    • col: number

      column index

    Returns void