Handsontable cell type
Add a spreadsheet editor in a popup, by using the Handsontable cell type.
The Handsontable cell type embeds a second grid instance as a cell editor (HOT-in-HOT). Use it when users need to search and select from a large dataset.
Usage
HOT-in-HOT opens by any of the following:
- F2 or Enter key is pressed while the cell is selected
- The triangle icon is clicked
- The cell content is double clicked
While HOT-in-HOT is opened, the text field above the HOT-in-HOT remains focused at all times.
Basic example
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
const colorData = [ ['yellow'], ['red'], ['orange'], ['green'], ['blue'], ['gray'], ['black'], ['white'],];
const manufacturerData = [ { name: 'BMW', country: 'Germany', owner: 'Bayerische Motoren Werke AG' }, { name: 'Chrysler', country: 'USA', owner: 'Chrysler Group LLC' }, { name: 'Nissan', country: 'Japan', owner: 'Nissan Motor Company Ltd' }, { name: 'Suzuki', country: 'Japan', owner: 'Suzuki Motor Corporation' }, { name: 'Toyota', country: 'Japan', owner: 'Toyota Motor Corporation' }, { name: 'Volvo', country: 'Sweden', owner: 'Zhejiang Geely Holding Group' },];
@Component({ selector: 'example1-handsontable-cell-type', standalone: true, imports: [HotTableModule], template: ` <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`,})export class AppComponent {
readonly data = [ ['Tesla', 2017, 'black', 'black'], ['Nissan', 2018, 'blue', 'blue'], ['Chrysler', 2019, 'yellow', 'black'], ['Volvo', 2020, 'white', 'gray'], ];
readonly gridSettings: GridSettings = { colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'], height: 'auto', autoWrapRow: true, autoWrapCol: true, columns: [ { type: 'handsontable', handsontable: { colHeaders: ['Marque', 'Country', 'Parent company'], autoColumnSize: true, data: manufacturerData, getValue() { const selection = this.getSelectedLast();
// Get the manufacturer name of the clicked row and ignore header // coordinates (negative values) return this.getSourceDataAtRow(Math.max(selection[0], 0)).name; }, }, }, { type: 'numeric' }, { type: 'handsontable', handsontable: { colHeaders: false, data: colorData, }, }, { type: 'handsontable', handsontable: { colHeaders: false, data: colorData, }, }, ] };}/* 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-handsontable-cell-type></example1-handsontable-cell-type></div>Keyboard shortcuts
| Key | Action |
|---|---|
| Escape | Close editor and cancel change |
| Enter | Close editor and apply change; move selection in the main HOT downwards or according to the enterMoves setting |
| Tab | Same as Enter, but move selection to the right or left according to the tabMoves setting |
| Arrow Down | Move selection in HOT-in-HOT downwards. No effect if last row is selected |
| Arrow Up | Move selection in HOT-in-HOT upwards. If the first row was selected, deselect. If HOT-in-HOT was deselected, behave as Enter but move main HOT selection upwards |
| Arrow Right | Move text cursor in the text field to the left. If cursor was at start, behave as Enter but move main HOT selection to the left |
| Arrow Left | Move text cursor in the text field to the right. If cursor was at end, behave as Tab |
Result
After configuring the Handsontable cell type, cells display a text input with a trigger icon. Activating the cell opens a second embedded grid that users can navigate and select from. The selected row value is written back to the parent cell.
Related articles
Related guides
Configuration options
Core methods
Hooks