Dropdown cell type
Collect user input with a searchable list of choices, by using the dropdown cell type.
The dropdown cell type lets users select a value from a predefined list. It is a simplified version of autocomplete with strict mode always on.
Overview
The dropdown cell type is based on an autocomplete cell type and can also be searchable.
Usage
This example shows the usage of the dropdown feature. Dropdown is based on Autocomplete cell type. All options used by autocomplete cell type apply to dropdown as well.
Internally, cell { type: 'dropdown' } is equivalent to cell { type:'autocomplete', strict: true, filter: false }. Therefore you can think of dropdown as a searchable <select>.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
@Component({ selector: 'example1-dropdown-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 = { height: 'auto', colHeaders: ['Car', 'Year', 'Chassis color', 'Bumper color'], autoWrapRow: true, autoWrapCol: true, columns: [ {}, { type: 'numeric' }, { type: 'dropdown', source: [ 'yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white', ], }, { type: 'dropdown', source: [ 'yellow', 'red', 'orange', 'green', 'blue', 'gray', 'black', 'white', ], }, ] };}
/* 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-dropdown-cell-type></example1-dropdown-cell-type></div>The source option
The source option can be provided in two formats:
Array of values
You can provide the source option as an array of values that will be used as the dropdown options.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
@Component({ selector: 'example2-dropdown-cell-type', standalone: true, imports: [HotTableModule], template: ` <div> <hot-table [data]="shipmentKVData" [settings]="gridSettings"></hot-table> </div>`})export class AppComponent { readonly shipmentKVData = [ ['Electronics and Gadgets','Los Angeles International Airport'], ['Medical Supplies', 'John F. Kennedy International Airport'], ['Auto Parts', 'Chicago O\'Hare International Airport'], ['Fresh Produce', 'London Heathrow Airport'], ['Textiles', 'Charles de Gaulle Airport'], ['Industrial Equipment', 'Dubai International Airport'], ['Pharmaceuticals', 'Tokyo Haneda Airport'], ['Consumer Goods', 'Beijing Capital International Airport'], ['Machine Parts', 'Singapore Changi Airport'], ['Food Products', 'Amsterdam Airport Schiphol'] ];
readonly airportKVData = [ 'Los Angeles International Airport', 'John F. Kennedy International Airport', 'Chicago O\'Hare International Airport', 'London Heathrow Airport', 'Charles de Gaulle Airport', 'Dubai International Airport', 'Tokyo Haneda Airport', 'Beijing Capital International Airport', 'Singapore Changi Airport', 'Amsterdam Airport Schiphol', 'Frankfurt Airport', 'Seoul Incheon International Airport', 'Toronto Pearson International Airport', 'Madrid-Barajas Airport', 'Bangkok Suvarnabhumi Airport', 'Munich International Airport', 'Sydney Kingsford Smith Airport', 'Barcelona-El Prat Airport', 'Kuala Lumpur International Airport', 'Zurich Airport' ];
readonly gridSettings: GridSettings = { height: 'auto', autoWrapRow: true, autoWrapCol: true, columns: [ { title: 'Shipment', }, { type: 'dropdown', source: this.airportKVData, title: 'Airport', }, ], };}/* 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-dropdown-cell-type></example2-dropdown-cell-type></div>Array of objects
You can provide the source option as an array of objects with key and value properties. The value property will be used as the dropdown option, while the entire object will be used as the value of the cell.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
@Component({ selector: 'example3-dropdown-cell-type', standalone: true, imports: [HotTableModule], template: ` <div> <hot-table [data]="shipmentKVData" [settings]="gridSettings"></hot-table> </div>`})export class AppComponent { readonly shipmentKVData = [ [ 'Electronics and Gadgets', { key: 'LAX', value: 'Los Angeles International Airport' }, ], [ 'Medical Supplies', { key: 'JFK', value: 'John F. Kennedy International Airport' } ], [ 'Auto Parts', { key: 'ORD', value: 'Chicago O\'Hare International Airport' } ], [ 'Fresh Produce', { key: 'LHR', value: 'London Heathrow Airport' } ], [ 'Textiles', { key: 'CDG', value: 'Charles de Gaulle Airport' } ], [ 'Industrial Equipment', { key: 'DXB', value: 'Dubai International Airport' } ], [ 'Pharmaceuticals', { key: 'HND', value: 'Tokyo Haneda Airport' } ], [ 'Consumer Goods', { key: 'PEK', value: 'Beijing Capital International Airport' } ], [ 'Machine Parts', { key: 'SIN', value: 'Singapore Changi Airport' } ], [ 'Food Products', { key: 'AMS', value: 'Amsterdam Airport Schiphol' } ] ];
readonly airportKVData = [ { key: 'LAX', value: 'Los Angeles International Airport' }, { key: 'JFK', value: 'John F. Kennedy International Airport' }, { key: 'ORD', value: 'Chicago O\'Hare International Airport' }, { key: 'LHR', value: 'London Heathrow Airport' }, { key: 'CDG', value: 'Charles de Gaulle Airport' }, { key: 'DXB', value: 'Dubai International Airport' }, { key: 'HND', value: 'Tokyo Haneda Airport' }, { key: 'PEK', value: 'Beijing Capital International Airport' }, { key: 'SIN', value: 'Singapore Changi Airport' }, { key: 'AMS', value: 'Amsterdam Airport Schiphol' }, { key: 'FRA', value: 'Frankfurt Airport' }, { key: 'ICN', value: 'Seoul Incheon International Airport' }, { key: 'YYZ', value: 'Toronto Pearson International Airport' }, { key: 'MAD', value: 'Madrid-Barajas Airport' }, { key: 'BKK', value: 'Bangkok Suvarnabhumi Airport' }, { key: 'MUC', value: 'Munich International Airport' }, { key: 'SYD', value: 'Sydney Kingsford Smith Airport' }, { key: 'BCN', value: 'Barcelona-El Prat Airport' }, { key: 'KUL', value: 'Kuala Lumpur International Airport' }, { key: 'ZRH', value: 'Zurich Airport' } ];
readonly gridSettings: GridSettings = { height: 'auto', autoWrapRow: true, autoWrapCol: true, columns: [ { title: 'Shipment', }, { type: 'dropdown', source: this.airportKVData, title: 'Airport', }, ], };}/* 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-dropdown-cell-type></example3-dropdown-cell-type></div>API methods
When working with object-based dropdown data, you can use methods like getSourceData(), getSourceDataAtCell(), getSourceDataAtRow() etc., to get the data in its original object format with both key and value properties. The getData() method will return only the value property’s content.
Set the dropdown width
By default, the dropdown list matches the width of the edited cell, so long options can be truncated. To let the list expand to fit its longest option, set trimDropdown to false.
| Setting | Description |
|---|---|
true (default) | Match the dropdown list’s width to the edited cell. |
false | Scale the dropdown list’s width to its longest option. |
In the example below, the Department (default) column trims the list to the cell, while the Department (full width) column expands it. Open a cell in each column to compare.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
const departments = [ 'Engineering and Platform Infrastructure', 'Marketing and Brand Communications', 'Financial Planning and Analysis', 'People Operations and Talent Acquisition', 'Customer Success and Enterprise Accounts',];
@Component({ selector: 'example4-dropdown-cell-type', standalone: true, imports: [HotTableModule], template: ` <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`,})export class AppComponent {
readonly data = [ ['Ana García', departments[0], departments[0]], ['James Okafor', departments[1], departments[1]], ['Li Wei', departments[2], departments[2]], ['Sofia Rossi', departments[3], departments[3]], ];
readonly gridSettings: GridSettings = { height: 'auto', colHeaders: ['Employee', 'Department (default)', 'Department (full width)'], autoWrapRow: true, autoWrapCol: true, columns: [ {}, { type: 'dropdown', source: departments, width: 140, // trim the list to the cell's width (default) trimDropdown: true, }, { type: 'dropdown', source: departments, width: 140, // expand the list to fit its longest option trimDropdown: 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> <example4-dropdown-cell-type></example4-dropdown-cell-type></div>Set the dropdown height
By default, the dropdown list shows up to 10 options before a scrollbar appears. To change how many options are visible at once, set visibleRows to the number of options you want to show.
In the example below, the Job title (default) column uses the default height, while the Job title (compact) column shows three options at a time. Open a cell in each column to compare.
/* file: app.component.ts */import { Component } from '@angular/core';import { GridSettings, HotTableModule} from '@handsontable/angular-wrapper';
const jobTitles = [ 'Software Engineer', 'Senior Software Engineer', 'Staff Engineer', 'Engineering Manager', 'Product Manager', 'Product Designer', 'Data Analyst', 'Data Scientist', 'Marketing Specialist', 'Account Executive', 'Customer Success Manager', 'Finance Analyst', 'Recruiter', 'Office Manager',];
@Component({ selector: 'example5-dropdown-cell-type', standalone: true, imports: [HotTableModule], template: ` <div> <hot-table [data]="data" [settings]="gridSettings"></hot-table> </div>`,})export class AppComponent {
readonly data = [ ['Ana García', 'Senior Software Engineer', 'Senior Software Engineer'], ['James Okafor', 'Product Manager', 'Product Manager'], ['Li Wei', 'Data Scientist', 'Data Scientist'], ['Sofia Rossi', 'Account Executive', 'Account Executive'], ];
readonly gridSettings: GridSettings = { height: 'auto', colHeaders: ['Employee', 'Job title (default)', 'Job title (compact)'], autoWrapRow: true, autoWrapCol: true, columns: [ {}, { type: 'dropdown', source: jobTitles, }, { type: 'dropdown', source: jobTitles, // show 3 options at a time, then scroll visibleRows: 3, }, ] };}
/* 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-dropdown-cell-type></example5-dropdown-cell-type></div>Result
After configuring the dropdown cell type, cells display a button that opens a dropdown list of options. Users can search the list by typing. Only values from the source list are accepted. The selected value is stored in the data source.
Keyboard shortcuts
The dropdown cell editor is an autocomplete editor with strict mode always on, so it uses the same keyboard shortcuts as Autocomplete strict mode. See the keyboard shortcuts reference for details.
Related articles
Related guides
Configuration options
Core methods
Hooks