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.
/* file: app.component.ts */import {Component, ViewChild, ViewEncapsulation, HostListener, ElementRef, inject} from '@angular/core';import { GridSettings, HotTableComponent, HotTableModule } from '@handsontable/angular-wrapper';
@Component({ selector: 'example1-selection', standalone: true, imports: [HotTableModule], template: ` <div class="example-controls-container"> <div class="controls"> <div class="theme-dropdown" #dropdownRef> <button class="theme-dropdown-trigger" type="button" aria-haspopup="listbox" [attr.aria-expanded]="isOpen" (click)="toggleDropdown()" > <span>{{ selectedLabel }}</span> <svg class="theme-dropdown-chevron" aria-hidden="true" width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M6 9l6 6l6 -6"/></svg> </button> @if (isOpen) { <ul class="theme-dropdown-menu" role="listbox"> @for (opt of options; track opt.value) { <li role="option" [attr.aria-selected]="selected === opt.value" (click)="selectOption(opt.value)" > {{ opt.label }} </li> } </ul> } </div> </div> </div> <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`, encapsulation: ViewEncapsulation.None})export class AppComponent { @ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;
isOpen = false; selected = 'multiple';
readonly options = [ { value: 'single', label: 'Single selection' }, { value: 'range', label: 'Range selection' }, { value: 'multiple', label: 'Multiple ranges selection' }, ];
readonly data = [ ['Ana García', 'Engineering', 'Senior Engineer', 95000, 'Madrid', 'Spain', 'F', 12, '2026-03-14'], ['James Okafor', 'Marketing', 'Product Manager', 88000, 'Lagos', 'Nigeria', 'M', 8, '2026-07-01'], ['Li Wei', 'Engineering', 'Frontend Dev', 82000, 'Shanghai', 'China', 'M', 5, '2026-01-10'], ['Maria Santos', 'HR', 'HR Specialist', 71000, 'Lisbon', 'Portugal','F', 3, '2026-11-20'], ['David Kim', 'Engineering', 'Backend Dev', 85000, 'Seoul', 'Korea', 'M', 7, '2026-08-05'], ['Emma Wilson', 'Marketing', 'SEO Analyst', 68000, 'London', 'UK', 'F', 2, '2026-02-14'], ['Ahmed Hassan', 'Finance', 'Controller', 92000, 'Cairo', 'Egypt', 'M', 10, '2026-06-30'], ['Sara Johansson', 'Engineering', 'QA Engineer', 78000, 'Stockholm', 'Sweden', 'F', 6, '2026-09-12'], ['Carlos Mendez', 'Sales', 'Account Manager', 74000, 'Mexico City', 'Mexico', 'M', 4, '2026-04-25'], ];
readonly gridSettings: GridSettings = { width: 'auto', height: 'auto', colWidths: 100, rowHeaders: true, colHeaders: true, selectionMode: 'multiple', // 'single', 'range' or 'multiple', autoWrapRow: true, autoWrapCol: true };
get selectedLabel(): string { return this.options.find((o) => o.value === this.selected)?.label || ''; }
private elementRef = inject(ElementRef);
toggleDropdown(): void { this.isOpen = !this.isOpen; }
selectOption(value: string): void { this.selected = value; this.isOpen = false; type selection = 'multiple' | 'single' | 'range' | undefined;
this.hotTable?.hotInstance?.updateSettings({ selectionMode: value as selection }); }
@HostListener('document:click', ['$event']) onDocumentClick(event: MouseEvent): void { if (!this.elementRef.nativeElement.querySelector('.theme-dropdown')?.contains(event.target)) { this.isOpen = false; } }
@HostListener('document:keydown', ['$event']) onKeydown(event: KeyboardEvent): void { if (event.key === 'Escape') { this.isOpen = false; } }}/* end-file */
/* file: app.config.ts */import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';import { registerAllModules } from 'handsontable/registry';import { HOT_GLOBAL_CONFIG, HotGlobalConfig, NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE } as HotGlobalConfig, }, ],};/* end-file */<div> <example1-selection></example1-selection></div>Get data from the selected ranges
To retrieve the selected cells as an array of arrays, you use the getSelected() or getSelectedRange() methods.
/* file: app.component.ts */import {Component, ViewChild, ViewEncapsulation} from '@angular/core';import { GridSettings, HotTableComponent, HotTableModule } from '@handsontable/angular-wrapper';import Handsontable from 'handsontable/base';
@Component({ selector: 'example2-selection', standalone: true, imports: [HotTableModule], template: ` <div class="example-controls-container"> <div class="controls"> <button id="getButton" (click)="getButtonClick()">Get data</button> </div> @if (output) { <output class="console" id="output"> {{ output }} </output> } </div> <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`, encapsulation: ViewEncapsulation.None})export class AppComponent { @ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;
readonly data = [ ['Ana García', 'Engineering', 'Senior Engineer', 95000, 'Madrid', 'Spain', 'F', 12, '2026-03-14'], ['James Okafor', 'Marketing', 'Product Manager', 88000, 'Lagos', 'Nigeria', 'M', 8, '2026-07-01'], ['Li Wei', 'Engineering', 'Frontend Dev', 82000, 'Shanghai', 'China', 'M', 5, '2026-01-10'], ['Maria Santos', 'HR', 'HR Specialist', 71000, 'Lisbon', 'Portugal','F', 3, '2026-11-20'], ['David Kim', 'Engineering', 'Backend Dev', 85000, 'Seoul', 'Korea', 'M', 7, '2026-08-05'], ['Emma Wilson', 'Marketing', 'SEO Analyst', 68000, 'London', 'UK', 'F', 2, '2026-02-14'], ['Ahmed Hassan', 'Finance', 'Controller', 92000, 'Cairo', 'Egypt', 'M', 10, '2026-06-30'], ['Sara Johansson', 'Engineering', 'QA Engineer', 78000, 'Stockholm', 'Sweden', 'F', 6, '2026-09-12'], ['Carlos Mendez', 'Sales', 'Account Manager', 74000, 'Mexico City', 'Mexico', 'M', 4, '2026-04-25'], ];
readonly gridSettings: GridSettings = { width: 'auto', height: 'auto', colWidths: 100, rowHeaders: true, colHeaders: true, outsideClickDeselects: false, selectionMode: 'multiple', // 'single', 'range' or 'multiple', autoWrapRow: true, autoWrapCol: true };
output = '';
getButtonClick(): void { const hot = this.hotTable?.hotInstance; const selected = hot?.getSelected() || []; let data: Handsontable.CellValue[] = [];
if (selected.length === 1) { data = hot?.getData(...selected[0]!) || []; } else { for (let i = 0; i < selected.length; i += 1) { const item = selected[i];
data.push(hot?.getData(...item)); } }
this.output = JSON.stringify(data); }}/* end-file */
/* file: app.config.ts */import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';import { registerAllModules } from 'handsontable/registry';import { HOT_GLOBAL_CONFIG, HotGlobalConfig, NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE } as HotGlobalConfig, }, ],};/* end-file */<div> <example2-selection></example2-selection></div>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.
/* file: app.component.ts */import {Component, ViewChild, ViewEncapsulation} from '@angular/core';import { GridSettings, HotTableComponent, HotTableModule } from '@handsontable/angular-wrapper';
@Component({ selector: 'example3-selection', standalone: true, imports: [HotTableModule], template: ` <div class="example-controls-container"> <div class="controls"> <button id="set-data-action" (click)="buttonClick()"> Click to modify the selected cells </button> </div> </div> <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`, encapsulation: ViewEncapsulation.None})export class AppComponent { @ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;
readonly data = [ ['Ana García', 'Engineering', 'Senior Engineer', 95000, 'Madrid', 'Spain', 'F', 12, '2026-03-14'], ['James Okafor', 'Marketing', 'Product Manager', 88000, 'Lagos', 'Nigeria', 'M', 8, '2026-07-01'], ['Li Wei', 'Engineering', 'Frontend Dev', 82000, 'Shanghai', 'China', 'M', 5, '2026-01-10'], ['Maria Santos', 'HR', 'HR Specialist', 71000, 'Lisbon', 'Portugal', 'F', 3, '2026-11-20'], ['David Kim', 'Engineering', 'Backend Dev', 85000, 'Seoul', 'Korea', 'M', 7, '2026-08-05'], ['Emma Wilson', 'Marketing', 'SEO Analyst', 68000, 'London', 'UK', 'F', 2, '2026-02-14'], ['Ahmed Hassan', 'Finance', 'Controller', 92000, 'Cairo', 'Egypt', 'M', 10, '2026-06-30'], ['Sara Johansson', 'Engineering', 'QA Engineer', 78000, 'Stockholm', 'Sweden', 'F', 6, '2026-09-12'], ['Carlos Mendez', 'Sales', 'Account Manager', 74000, 'Mexico City', 'Mexico', 'M', 4, '2026-04-25'], ];
readonly gridSettings: GridSettings = { width: 'auto', height: 'auto', colWidths: 100, rowHeaders: true, colHeaders: true, outsideClickDeselects: false, selectionMode: 'multiple', // 'single', 'range' or 'multiple', autoWrapRow: true, autoWrapCol: true };
output = '';
buttonClick(): void { const hot = this.hotTable?.hotInstance; const selected = hot?.getSelected() || [];
hot?.suspendRender();
for (let index = 0; index < selected.length; index += 1) { const [row1, column1, row2, column2] = selected[index]; const startRow = Math.max(Math.min(row1, row2), 0); const endRow = Math.max(row1, row2); const startCol = Math.max(Math.min(column1, column2), 0); const endCol = Math.max(column1, column2);
for (let rowIndex = startRow; rowIndex <= endRow; rowIndex += 1) { for ( let columnIndex = startCol; columnIndex <= endCol; columnIndex += 1 ) { hot?.setDataAtCell(rowIndex, columnIndex, 'data changed'); hot?.setCellMeta(rowIndex, columnIndex, 'className', 'c-red'); } } }
hot?.render(); hot?.resumeRender(); }}/* end-file */
/* file: app.config.ts */import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';import { registerAllModules } from 'handsontable/registry';import { HOT_GLOBAL_CONFIG, HotGlobalConfig, NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE } as HotGlobalConfig, }, ],};/* end-file */<div> <example3-selection></example3-selection></div>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.
/* file: app.component.ts */import { Component, ViewEncapsulation } from '@angular/core';import { GridSettings, HotTableModule } from '@handsontable/angular-wrapper';
@Component({ selector: 'example4-selection', standalone: true, imports: [HotTableModule], styles: [` #example4 td.area { background-color: rgba(75, 137, 255, 0.2); } #example4 td.area.area-1 { background-color: rgba(75, 137, 255, 0.4); } #example4 td.area.area-2 { background-color: rgba(75, 137, 255, 0.6); } `], template: `<div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`, encapsulation: ViewEncapsulation.None})export class AppComponent { readonly data = [ ['Ana García', 'Engineering', 'Senior Engineer', 95000, 'Madrid', 'Spain', 'F', 12, '2026-03-14'], ['James Okafor', 'Marketing', 'Product Manager', 88000, 'Lagos', 'Nigeria', 'M', 8, '2026-07-01'], ['Li Wei', 'Engineering', 'Frontend Dev', 82000, 'Shanghai', 'China', 'M', 5, '2026-01-10'], ['Maria Santos', 'HR', 'HR Specialist', 71000, 'Lisbon', 'Portugal', 'F', 3, '2026-11-20'], ['David Kim', 'Engineering', 'Backend Dev', 85000, 'Seoul', 'Korea', 'M', 7, '2026-08-05'], ['Emma Wilson', 'Marketing', 'SEO Analyst', 68000, 'London', 'UK', 'F', 2, '2026-02-14'], ];
readonly gridSettings: GridSettings = { width: 'auto', height: 'auto', colWidths: 100, rowHeaders: true, colHeaders: true, outsideClickDeselects: false, selectionMode: 'multiple', autoWrapRow: true, autoWrapCol: true, };}/* end-file */
/* file: app.config.ts */import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';import { registerAllModules } from 'handsontable/registry';import { HOT_GLOBAL_CONFIG, HotGlobalConfig, NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE } as HotGlobalConfig, }, ],};/* end-file */<div> <example4-selection></example4-selection></div>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.
/* file: app.component.ts */import { Component, ViewChild, ViewEncapsulation } from '@angular/core';import { GridSettings, HotTableComponent, HotTableModule } from '@handsontable/angular-wrapper';
@Component({ selector: 'example5-selection', standalone: true, imports: [HotTableModule], template: ` <div class="example-controls-container"> <div class="controls"> <button (click)="selectCell()">Select cell B2</button> <button (click)="selectRange()">Select range B2:D4</button> <button (click)="deselect()">Deselect</button> </div> </div> <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`, encapsulation: ViewEncapsulation.None})export class AppComponent { @ViewChild(HotTableComponent, { static: false }) readonly hotTable!: HotTableComponent;
readonly data = [ ['Ana García', 'Engineering', 'Senior Engineer', 95000, 12, '2026-03-14'], ['James Okafor', 'Marketing', 'Product Manager', 88000, 8, '2026-07-01'], ['Li Wei', 'Engineering', 'Frontend Dev', 82000, 5, '2026-01-10'], ['Maria Santos', 'HR', 'HR Specialist', 71000, 3, '2026-11-20'], ['David Kim', 'Engineering', 'Backend Dev', 85000, 7, '2026-08-05'], ['Emma Wilson', 'Marketing', 'SEO Analyst', 68000, 2, '2026-02-14'], ];
readonly gridSettings: GridSettings = { width: 'auto', height: 'auto', colWidths: 100, rowHeaders: true, colHeaders: true, outsideClickDeselects: false, autoWrapRow: true, autoWrapCol: true, };
selectCell(): void { // Select a single cell: row 1, col 1 (B2) this.hotTable?.hotInstance?.selectCell(1, 1); }
selectRange(): void { // Select a range: row 1, col 1 to row 3, col 3 (B2:D4) this.hotTable?.hotInstance?.selectCell(1, 1, 3, 3); }
deselect(): void { this.hotTable?.hotInstance?.deselectCell(); }}/* end-file */
/* file: app.config.ts */import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core';import { registerAllModules } from 'handsontable/registry';import { HOT_GLOBAL_CONFIG, HotGlobalConfig, NON_COMMERCIAL_LICENSE } from '@handsontable/angular-wrapper';
// register Handsontable's modulesregisterAllModules();
export const appConfig: ApplicationConfig = { providers: [ provideZoneChangeDetection({ eventCoalescing: true }), { provide: HOT_GLOBAL_CONFIG, useValue: { license: NON_COMMERCIAL_LICENSE } as HotGlobalConfig, }, ],};/* end-file */<div> <example5-selection></example5-selection></div>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.