Interface SelectionModelIf

What is selected in a table – a list of rectangles (CellRange). The implementation is SelectionModel; every table gets its own, or you pass one via TableOptionsIf.getSelectionModel. Changes are reported to EventListenerIf.onSelectionChanged.

Example

override onSelectionChanged(model: SelectionModelIf): void {
// rows with at least one selected cell – also for "row"/"column" selections (their ranges are unbounded:
// r2/c2 = Number.MAX_SAFE_INTEGER, so (r2 - r1 + 1) * (c2 - c1 + 1) is no cell count)
const rowCount = tableModel.getBodyModel().getRowCount();
const rows = model.getMergedRowIndices(rowCount);
console.log(model.hasSelection() ? `${rows.length} rows with selected cells` : "nothing selected");
}

See

Training: Select cells, rows and ranges – and copy them

Hierarchy

  • SelectionModelIf

Implemented by

Methods

  • Called by the table on a click: starts a selection at this cell, depending on selection type and mode.

    Parameters

    • rowIndex: number
    • columnIndex: number

    Returns void

  • The indices of all rows that contain at least one selected cell, sorted ascending.

    Ranges that cover all rows (selection type "column") and selectAll need rowCount to be listed; without it they are skipped. Implementations written before rowCount existed may ignore it.

    Parameters

    • Optional rowCount: number

      number of body rows (optional): limits the result to 0 … rowCount - 1

    Returns number[]

    Example

    const sm = tableApi.getSelectionModel();
    const rowIndices = sm?.getMergedRowIndices(tableModel.getBodyModel().getRowCount()) ?? [];
  • Checks if a specific cell in a grid is selected.

    Parameters

    • row: number

      The row index of the cell to check.

    • col: number

      The column index of the cell to check.

    Returns boolean

    • Returns true if the cell is selected, otherwise false.
  • Toggles the selection state of a point at the specified row and column in a grid.

    Parameters

    • row: number

      The row index of the point to toggle.

    • col: number

      The column index of the point to toggle.

    Returns void