Row Selection in Apex Grid
The Apex grid supports single- and multi-row selection with an optional dedicated checkbox column. Selection works programmatically and via the keyboard, and the checkbox column is purely cosmetic: hiding it does not disable selection.
Enabling selection
grid.selection = {
enabled: true,
mode: 'multiple', // 'single' | 'multiple'
showCheckboxColumn: true,
};
Configuration
type GridSelectionConfiguration<T> = {
enabled?: boolean;
mode?: 'single' | 'multiple';
showCheckboxColumn?: boolean;
isRowSelectable?: (row: T) => boolean;
};
- mode controls the selection cardinality. Defaults to
'multiple'. - showCheckboxColumn renders a leading checkbox column. Defaults to
false. - isRowSelectable decides per row whether it can be selected. Unset, every row is selectable, pinned rows included.
Rows that cannot be selected
isRowSelectable keeps chosen rows out of selection, such as a pinned total row that is a summary rather than a record:
grid.selection = {
enabled: true,
showCheckboxColumn: true,
isRowSelectable: (row) => row !== totalRow,
};
A row the predicate rejects shows no checkbox (its cell stays, so the columns line up) and carries no aria-selected. Checkbox and cell clicks, Shift and Ctrl/Cmd clicks, Space, Select all, selectRow, selectedRows = ... and setState all skip it, and the header checkbox counts only selectable rows. When selection or data is reassigned, selected rows the predicate now rejects are dropped through the cancellable rowSelecting event.
Programmatic API
await grid.selectRow(row);
await grid.deselectRow(row);
await grid.toggleRowSelection(row);
await grid.selectAllRows();
grid.clearSelection();
const isSelected = grid.isRowSelected(row);
grid.selectedRows = [row1, row2]; // setter routes through `rowSelecting`
const current = grid.selectedRows; // getter
Events
- rowSelecting: cancellable; fires before a row's selection state changes. In multi mode, this fires once per affected row.
- rowSelected: fires after the row's selection state has changed.
Use the rowSelecting event to enforce business rules (for example, prevent deselecting the last row) by calling event.preventDefault() inside the handler.
Keyboard
The grid follows the WCAG 2.2 AA grid pattern: Space toggles the focused row, Shift+Space extends the selection range from the anchor, and Ctrl+A selects all rows in multiple mode.