Skip to content

Collect user input with a searchable list of choices, by using the dropdown cell type.

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>.

JavaScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
return (
<HotTable
height="auto"
data={[
['Tesla', 2017, 'black', 'black'],
['Nissan', 2018, 'blue', 'blue'],
['Chrysler', 2019, 'yellow', 'black'],
['Volvo', 2020, 'white', 'gray'],
]}
colHeaders={['Car', 'Year', 'Chassis color', 'Bumper color']}
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'],
},
]}
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
/>
);
};
export default ExampleComponent;
TypeScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
return (
<HotTable
height="auto"
data={[
['Tesla', 2017, 'black', 'black'],
['Nissan', 2018, 'blue', 'blue'],
['Chrysler', 2019, 'yellow', 'black'],
['Volvo', 2020, 'white', 'gray'],
]}
colHeaders={['Car', 'Year', 'Chassis color', 'Bumper color']}
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'],
},
]}
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
/>
);
};
export default ExampleComponent;

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.

JavaScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
const 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'],
];
const 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',
];
return (
<HotTable
height="auto"
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
data={shipmentKVData}
columns={[
{
title: 'Shipment',
},
{
type: 'dropdown',
source: airportKVData,
title: 'Airport',
},
]}
/>
);
};
export default ExampleComponent;
TypeScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
const 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'],
];
const 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',
];
return (
<HotTable
height="auto"
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
data={shipmentKVData}
columns={[
{
title: 'Shipment',
},
{
type: 'dropdown',
source: airportKVData,
title: 'Airport',
},
]}
/>
);
};
export default ExampleComponent;

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.

JavaScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
const 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' }],
];
const 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' },
];
return (
<HotTable
height="auto"
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
data={shipmentKVData}
columns={[
{
title: 'Shipment',
},
{
type: 'dropdown',
source: airportKVData,
title: 'Airport',
},
]}
/>
);
};
export default ExampleComponent;
TypeScript
import { HotTable } from '@handsontable/react-wrapper';
import { registerAllModules } from 'handsontable/registry';
// register Handsontable's modules
registerAllModules();
const ExampleComponent = () => {
const 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' }],
];
const 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' },
];
return (
<HotTable
height="auto"
autoWrapRow={true}
autoWrapCol={true}
licenseKey="non-commercial-and-evaluation"
data={shipmentKVData}
columns={[
{
title: 'Shipment',
},
{
type: 'dropdown',
source: airportKVData,
title: 'Airport',
},
]}
/>
);
};
export default ExampleComponent;

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.

Related guides

Configuration options

Core methods

Hooks