Selection
Select a single cell, a range of adjacent cells, or multiple non-adjacent ranges of cells.
Use the selection API to control how users select cells — single cells, ranges, columns, or rows — and to read or set selections programmatically.
Overview
Selection enables you to select a single cell or ranges of cells within Handsontable. Once selected, you can retrieve data from the cell, edit the cell’s contents, or change the style of the cell.
Basic configuration
With this feature, you can select single cells or ranges of cells across a grid. Easily retrieve the coordinates of the selected cells to clear or change the cells’ content.
Use ⌘ on Mac or Ctrl on Windows to select non-adjacent ranges of cells.
Click a column header to select all cells in that column. Click a row header to select all cells in that row. Both require colHeaders or rowHeaders to be enabled.
Select ranges
There are different modes in which you can use this plugin. Choose between selecting a single cell, a range of adjacent cells, and multiple ranges of non-contiguous cells.
Possible values of selectionMode:
single- You can select a single cell.range- You can select multiple cells within a single rangeselected.multiple- Multiple non-contiguous ranges of cells can be selected.
Get data from the selected ranges
To retrieve the selected cells as an array of arrays, you use the getSelected() or getSelectedRange() methods.
Modify the selected cells
You may want to delete, format, or otherwise change the selected cells. For example, you can change a value or add CSS classes to the selected cells using the demo below.
Style the selection area
You can change the background color of selected cells using CSS. The base selection color is defined in the .area class.
When using multiple non-adjacent selections (Cmd/Ctrl + click), each additional selection layer receives a numbered class: area-1 for the second layer, area-2 for the third, and so on. Each class is cumulative — a cell in the second layer has both area and area-1.
The example below customizes the color of each selection layer using these CSS classes.
Unfortunately, there is no easy way to change the border color of the selection.
Select cells programmatically
Use selectCell() to select a single cell or a range of cells from code. Pass the start and end row/column indices to define a range. Use deselectCell() to clear the selection.
Jump across the grid’s edges
When you use keyboard navigation to cross an edge of the grid, you can set cell selection to jump to the opposite edge.
Jump across vertical edges
To enable jumping across the left and right edges:
- Set the
autoWrapRowconfiguration option totrue.
To jump across a vertical edge:
- When cell selection is on a row’s first cell, press ←.
- When cell selection is on a row’s last cell, press →, or press Tab.
Jump across horizontal edges
To enable jumping across the top and bottom edges:
- Set the
autoWrapColconfiguration option totrue.
To jump across a horizontal edge:
- When cell selection is on a column’s first cell, press ↑.
- When cell selection is on a column’s last cell, press ↓, or press Enter.
Related keyboard shortcuts
| Windows | macOS | Action | Excel | Sheets |
|---|---|---|---|---|
| Ctrl+A | ⌘+A | Select all cells | ✓ | ✓ |
| Ctrl+Shift+Space | ⌘+⇧+Space | Select all cells and headers | ✓ | ✓ |
| Ctrl+Space | ⌃+Space | Select the entire column | ✓ | ✓ |
| Shift+Space | ⇧+Space | Select the entire row | ✓ | ✓ |
| Ctrl+Shift+↑ | ⌘+⇧+↑ | Extend the selection to the first cell of the current column** | ✓ | ✓ |
| Ctrl+Shift+↓ | ⌘+⇧+↓ | Extend the selection to the last cell of the current column** | ✓ | ✓ |
| Ctrl+Shift+← | ⌘+⇧+← | Extend the selection to the leftmost cell of the current row** | ✓ | ✓ |
| Ctrl+Shift+→ | ⌘+⇧+→ | Extend the selection to the rightmost cell of the current row** | ✓ | ✓ |
| Shift + Arrow keys | ⇧ + Arrow keys | Extend the selection by one cell | ✓ | ✓ |
| Shift+Home | ⇧+Home | Extend the selection to the first non-frozen cell of the current row* | ✓ | ✗ |
| Shift+End | ⇧+End | Extend the selection to the last non-frozen cell of the current row* | ✗ | ✗ |
| Shift+Page Up | ⇧+Page Up | Extend the selection by one screen up | ✓ | ✓ |
| Shift+Page Down | ⇧+Page Down | Extend the selection by one screen down | ✓ | ✓ |
| Ctrl+Enter | ⌘+Enter | Fill the selected range of cells with the value of the active cell | ✗ | ✓ |
| Delete | Delete | Clear the contents of the selected cells | ✓ | ✓ |
| Backspace | Backspace | Clear the contents of the selected cells | ✓ | ✓ |
* This action depends on your layout direction.
** In case of multiple selection layers, only the last selection layer gets extended.
Related API reference
Configuration options
Core methods
Hooks
Plugins
Result
Users can select cells using the configured mode — single cell, range, or multiple ranges. Programmatic selections take effect immediately and fire the relevant selection hooks.