Skip to content

Autocomplete cell type

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

The autocomplete cell type provides a text input with suggestions from a predefined list. Use it when users should choose from known values but can also type freely.

Overview

You can edit the autocomplete-typed cells in three different ways:

  • Flexible mode
  • Strict mode
  • Strict mode with asynchronous data

In all three modes, the source option can be provided in two formats:

  • An array of values
  • An array of objects with key and value properties

In all three modes, validation runs when a value is written to a cell. Values that are already in the data source when the grid loads are not validated. To check and mark them, call validateCells() after the grid is created.

Autocomplete flexible mode

This example uses the autocomplete feature in the default flexible mode. In this mode, the user can choose one of the suggested options while typing or enter a custom value that is not included in the suggestions.

The visibleRows option sets how many suggestions the dropdown shows without scrolling. The default is 10 rows. The Warehouse column sets visibleRows: 4, so the dropdown shows up to four suggestions at a time and scrolls to reveal the rest. If there is not enough free space on the screen for four rows, the dropdown shows fewer.

The trimDropdown option controls the dropdown’s width. By default (trimDropdown: true), the dropdown matches the width of the edited cell, which can truncate long suggestions. The Product column sets trimDropdown: false, so the dropdown expands to fit its widest suggestion. It can grow wider than the cell, but never narrower.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const warehouses = [
'Seattle',
'Denver',
'Portland',
'Austin',
'Minneapolis',
'Boston',
'Chicago',
'Phoenix',
'Atlanta',
'Dallas',
'San Jose',
'Columbus',
];
const products = [
'Stainless Steel Water Bottle',
'Wireless Mouse',
'Ergonomic Office Chair',
'USB-C Charging Cable',
'Aluminum Water Filter',
'Canvas Tote Bag',
'USB-C Hub',
'Ceramic Mug Set',
'Desk Lamp',
'Laptop Stand',
'Bluetooth Speaker',
'Standing Desk',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Harbor Goods', 'SKU-4821', 'Seattle', 'Stainless Steel Water Bottle'],
['Alpine Supply Co.', 'SKU-0093', 'Denver', 'Wireless Mouse'],
['Cascade Distributors', 'SKU-1170', 'Portland', 'Ergonomic Office Chair'],
['Summit Trading', 'SKU-2208', 'Austin', 'USB-C Charging Cable'],
['Northgate Wholesale', 'SKU-3341', 'Minneapolis', 'Aluminum Water Filter'],
],
colHeaders: ['Supplier', 'SKU', 'Warehouse', 'Product'],
columns: [
{
type: 'autocomplete',
source: [
'Harbor Goods',
'Alpine Supply Co.',
'Cascade Distributors',
'Summit Trading',
'Northgate Wholesale',
'Nordic Traders',
],
strict: false,
},
{},
{
type: 'autocomplete',
source: warehouses,
strict: false,
visibleRows: 4,
},
{
type: 'autocomplete',
source: products,
strict: false,
trimDropdown: false,
width: 120,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example1">
<HotTable :settings="hotSettings" />
</div>
</template>

Autocomplete strict mode

This is the same example as above, the difference being that autocomplete now runs in strict mode. In this mode, the autocomplete cells will only accept values that are defined in the source array. The mouse and keyboard bindings are identical to the handsontable cell type but with the differences below:

  • If there is at least one option visible, there always is a selection in HOT-in-HOT
  • When the first row is selected, pressing Arrow Up does not deselect HOT-in-HOT. Instead, it behaves as the Enter key but moves the selection in the main HOT upwards

In strict mode, the allowInvalid option determines the behavior in the case of manual user input:

  • allowInvalid: true optional - allows manual input of a value that does not exist in the source, the field background is highlighted in red, and the selection advances to the next cell
  • allowInvalid: false - does not allow manual input of a value that does not exist in the source, the Enter key is ignored, and the editor field remains open
Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const ALLOWED_TAGS = ['BR', 'TABLE', 'THEAD', 'TBODY', 'TR', 'TD', 'TH'];
const ALLOWED_ATTRIBUTES = ['colspan', 'rowspan'];
const DROPPED_TAGS = ['SCRIPT', 'STYLE', 'TEXTAREA', 'TITLE'];
// Handsontable has no built-in sanitizer since v18.0, and `sanitizer` is grid-level:
// it also filters pasted HTML, so the table tags have to survive -- otherwise pasting
// a range degrades to plain text. In production, use a vetted library such as DOMPurify.
// See https://handsontable.com/docs/security/
const sanitizeHeader = (html: string): string => {
const template = document.createElement('template');
template.innerHTML = html;
template.content.querySelectorAll('*').forEach((element) => {
if (DROPPED_TAGS.includes(element.tagName)) {
// Unwrapping these would promote their source text into the output
element.remove();
} else if (ALLOWED_TAGS.includes(element.tagName)) {
Array.from(element.attributes).forEach((attribute) => {
if (!ALLOWED_ATTRIBUTES.includes(attribute.name)) {
element.removeAttribute(attribute.name);
}
});
} else {
// Unwrap a disallowed element, keeping its text content
element.replaceWith(...Array.from(element.childNodes));
}
});
return template.innerHTML;
};
const warehouses = [
'Seattle',
'Denver',
'Portland',
'Austin',
'Minneapolis',
'Boston',
'Chicago',
'Phoenix',
'Atlanta',
'Dallas',
'San Jose',
'Columbus',
];
const products = [
'Stainless Steel Water Bottle',
'Wireless Mouse',
'Ergonomic Office Chair',
'USB-C Charging Cable',
'Aluminum Water Filter',
'Canvas Tote Bag',
'USB-C Hub',
'Ceramic Mug Set',
'Desk Lamp',
'Laptop Stand',
'Bluetooth Speaker',
'Standing Desk',
];
const suppliers = [
'Harbor Goods',
'Alpine Supply Co.',
'Cascade Distributors',
'Summit Trading',
'Northgate Wholesale',
'Nordic Traders',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Harbor Goods', 'SKU-4821', 'Seattle', 'Stainless Steel Water Bottle'],
['Alpine Supply Co.', 'SKU-0093', 'Denver', 'Wireless Mouse'],
['Cascade Distributors', 'SKU-1170', 'Portland', 'Ergonomic Office Chair'],
['Summit Trading', 'SKU-2208', 'Austin', 'USB-C Charging Cable'],
['Northgate Wholesale', 'SKU-3341', 'Minneapolis', 'Aluminum Water Filter'],
],
colHeaders: ['Supplier<br>(allowInvalid false)', 'SKU', 'Warehouse', 'Product<br>(allowInvalid true)'],
columns: [
{
type: 'autocomplete',
source: suppliers,
strict: true,
allowInvalid: false,
},
{},
{
type: 'autocomplete',
source: warehouses,
strict: true,
},
{
type: 'autocomplete',
source: products,
strict: true,
allowInvalid: true, // true is default
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
sanitizer: sanitizeHeader,
});
</script>
<template>
<div id="example2">
<HotTable :settings="hotSettings" />
</div>
</template>

Autocomplete strict mode with asynchronous data

Autocomplete can also use asynchronous data sources. In the example below, suggestions for the “Supplier” column are loaded from the server with the Fetch API. To load data from a remote source, assign a function to the source option. The function receives the query string and the process callback. Call process() with the result array when the request completes.

Handsontable DataGrid ignores a response that arrives after the editor closed - including a close you may not notice, such as scrolling the edited cell out of view - and it ignores a response that a newer query has superseded, which happens as you type. Call process() whenever the request completes, even late.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Harbor Goods', 'SKU-4821', 'Seattle', 'Stainless Steel Water Bottle'],
['Alpine Supply Co.', 'SKU-0093', 'Denver', 'Wireless Mouse'],
['Cascade Distributors', 'SKU-1170', 'Portland', 'Ergonomic Office Chair'],
['Summit Trading', 'SKU-2208', 'Austin', 'USB-C Charging Cable'],
['Northgate Wholesale', 'SKU-3341', 'Minneapolis', 'Aluminum Water Filter'],
],
colHeaders: ['Supplier', 'SKU', 'Warehouse', 'Product'],
columns: [
{
type: 'autocomplete',
source(_query: string, process: (data: string[]) => void) {
fetch('/docs/scripts/json/autocomplete.json')
.then((response) => response.json())
.then((response) => process(response.data));
},
strict: true,
},
{}, // SKU is a default text column
{}, // Warehouse is a default text column
{}, // Product is a default text column
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example3">
<HotTable :settings="hotSettings" />
</div>
</template>

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

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
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',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: shipmentKVData,
columns: [
{
title: 'Shipment',
},
{
type: 'autocomplete',
source: airportKVData,
title: 'Airport',
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example4">
<HotTable :settings="hotSettings" />
</div>
</template>

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 autocomplete suggestion, while the entire object will be used as the value of the cell.

To show a label and keep a short code, put the label in value and the code in key. The cell shows value and stores the whole object, so getSourceDataAtCell() returns that object, with the code in its key property.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
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' },
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: shipmentKVData,
columns: [
{
title: 'Shipment',
},
{
type: 'autocomplete',
source: airportKVData,
title: 'Airport',
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example5">
<HotTable :settings="hotSettings" />
</div>
</template>

API methods

When working with object-based autocomplete 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 value.

Writing a plain value

You don’t have to build the object yourself. When you write a plain value into the cell, Handsontable looks it up among the value properties of the source array. On a match, the cell stores the whole matching object, with its key.

This applies to every way a value reaches the cell:

  • picking an option in the editor
  • typing an option’s text and pressing Enter
  • pasting text, including a paste from another application and a paste as plain text (Ctrl/Cmd + Shift + V)
  • calling setDataAtCell() or populateFromArray()

A value that matches no option is stored as you wrote it. In strict mode such a value fails validation.

The lookup compares the text the cell displays, so a numeric value matches its string form. It’s skipped when source is a function, because the options aren’t known until the function answers.

Object values

The value property can be an object, for example a record from your API. Use the sourceLabel option to tell the cell which text to display for it:

  • A string reads a property of the object. Use dot notation for a nested property or an array item, for example 'address.city' or 'aliases.0'.
  • A function receives the object and returns the text.

In the example below, the function shows the city next to the name of each airport.

columns: [{
type: 'autocomplete',
source: [
{ key: 'LHR', value: { name: 'London Heathrow Airport', city: 'London' } },
{ key: 'CDG', value: { name: 'Charles de Gaulle Airport', city: 'Paris' } },
],
sourceLabel: (airport) => `${airport.city} - ${airport.name}`,
}],

The cell, the list of options, the filter of typed text, and pasted text all use that label. The cell itself stores the whole source entry, so getSourceDataAtCell() returns the object with every property.

To change an entry, replace it in source and in the cells that hold it. Don’t change the entry object in place. Depending on how the value was written, a cell holds either the source entry itself or a copy of it: picking an option for an empty cell and pasting store the entry, while picking an option for a cell that already holds a value, undo, and redo store a copy. A copy is a plain object, even when the entry is an instance of a class.

Each entry needs a unique label. If two entries display the same label, picking or pasting that label stores the first of them. An entry whose label resolves to nothing, for example a missing property, isn’t listed as an option.

The sourceLabel option changes only how an object value is displayed. A string or number value is displayed as it is, and a source without the option works exactly as before.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
type Airport = {
name: string;
city: string;
country: string;
};
// each `value` is an object, so the cell stores the whole airport, not only its name
const airports = [
{ key: 'LAX', value: { name: 'Los Angeles International Airport', city: 'Los Angeles', country: 'USA' } },
{ key: 'JFK', value: { name: 'John F. Kennedy International Airport', city: 'New York', country: 'USA' } },
{ key: 'LHR', value: { name: 'London Heathrow Airport', city: 'London', country: 'United Kingdom' } },
{ key: 'CDG', value: { name: 'Charles de Gaulle Airport', city: 'Paris', country: 'France' } },
{ key: 'HND', value: { name: 'Tokyo Haneda Airport', city: 'Tokyo', country: 'Japan' } },
{ key: 'SIN', value: { name: 'Singapore Changi Airport', city: 'Singapore', country: 'Singapore' } },
];
const shipments = [
['Electronics and Gadgets', airports[0]],
['Medical Supplies', airports[1]],
['Fresh Produce', airports[2]],
['Textiles', airports[3]],
['Pharmaceuticals', airports[4]],
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: shipments,
columns: [
{
title: 'Shipment',
},
{
type: 'autocomplete',
source: airports,
// display the city and the name of each airport
sourceLabel: (airport: Airport) => `${airport.city} - ${airport.name}`,
title: 'Destination airport',
width: 400,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example10">
<HotTable :settings="hotSettings" />
</div>
</template>

The filter option

By default, the autocomplete dropdown hides options that don’t match what the user is typing. Set filter: false to always show the full list of source options, regardless of the current input. This is useful when you want to give users a visual reference of all available choices while they type.

The left column uses the default behavior (filter: true) — options are narrowed as you type. The right column has filter: false — all options remain visible no matter what you enter.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const fruits: string[] = [
'Apple',
'Apricot',
'Avocado',
'Banana',
'Blueberry',
'Cherry',
'Grape',
'Lemon',
'Lime',
'Mango',
'Orange',
'Peach',
'Pear',
'Pineapple',
'Plum',
'Raspberry',
'Strawberry',
'Watermelon',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Apple', 'Apple'],
['Banana', 'Banana'],
['Cherry', 'Cherry'],
['Mango', 'Mango'],
['Orange', 'Orange'],
],
colHeaders: ['Filter: true (default)', 'Filter: false'],
columns: [
{
type: 'autocomplete',
source: fruits,
strict: false,
// filter: true is the default — only matching options are shown
},
{
type: 'autocomplete',
source: fruits,
strict: false,
// don't hide options that don't match the search query
filter: false,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example6">
<HotTable :settings="hotSettings" />
</div>
</template>

The filteringCaseSensitive option

By default, the autocomplete search is case-insensitive — typing "bl" matches both "Black" and "blue". Set filteringCaseSensitive: true to require an exact case match when filtering suggestions.

The left column uses the default case-insensitive behavior. The right column has filteringCaseSensitive: true — only options whose case matches the typed characters are shown.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const colors: string[] = [
'Black',
'Blue',
'brown',
'cyan',
'Gray',
'green',
'Lime',
'Magenta',
'Navy',
'olive',
'orange',
'Pink',
'Purple',
'Red',
'silver',
'Teal',
'White',
'Yellow',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Black', 'Black'],
['Blue', 'Blue'],
['Gray', 'Gray'],
['Red', 'Red'],
['White', 'White'],
],
colHeaders: ['Case-insensitive (default)', 'Case-sensitive'],
columns: [
{
type: 'autocomplete',
source: colors,
strict: false,
// filteringCaseSensitive: false is the default — typing "bl" matches "Black" and "blue"
},
{
type: 'autocomplete',
source: colors,
strict: false,
// match case while searching autocomplete options
filteringCaseSensitive: true,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example7">
<HotTable :settings="hotSettings" />
</div>
</template>

The sortByRelevance option

By default, the autocomplete dropdown shows suggestions in the order you provide them in the source array. Set sortByRelevance: false to sort suggestions alphabetically instead.

The left column uses the default behavior (sortByRelevance: true) — suggestions keep the order from source. The right column has sortByRelevance: false — suggestions sort alphabetically.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const statuses: string[] = [
'Backlog',
'In progress',
'Blocked',
'Done',
'Cancelled',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
['Backlog', 'Backlog'],
['In progress', 'In progress'],
['Blocked', 'Blocked'],
['Done', 'Done'],
['Cancelled', 'Cancelled'],
],
colHeaders: ['Source order (default)', 'Alphabetical order'],
columns: [
{
type: 'autocomplete',
source: statuses,
strict: false,
// sortByRelevance: true is the default — suggestions keep the order from `source`
},
{
type: 'autocomplete',
source: statuses,
strict: false,
// sort suggestions alphabetically instead of using the `source` order
sortByRelevance: false,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example8">
<HotTable :settings="hotSettings" />
</div>
</template>

The allowHtml option

By default, the autocomplete dropdown and cell renderer display source values as plain text, so any HTML tags they contain show up literally. Set allowHtml: true to render source values as HTML instead, for example to show colored status labels.

The left column uses the default behavior (allowHtml: false) — HTML tags in source show up as plain text. The right column has allowHtml: true — the same source values render as colored labels.

Vue
<script setup lang="ts">
import { ref } from 'vue';
import { HotTable } from '@handsontable/vue3';
import { registerAllModules } from 'handsontable/registry';
import type { GridSettings } from 'handsontable/settings';
// register Handsontable's modules
registerAllModules();
const stockStatuses: string[] = [
'<span style="color: #1a7f37">In stock</span>',
'<span style="color: #b35900">Low stock</span>',
'<span style="color: #c92a2a">Out of stock</span>',
'<span style="color: #495057">Backordered</span>',
'<span style="color: #495057">Discontinued</span>',
];
const hotSettings = ref<GridSettings>({
height: 'auto',
autoWrapRow: true,
autoWrapCol: true,
data: [
[stockStatuses[0], stockStatuses[0]],
[stockStatuses[1], stockStatuses[1]],
[stockStatuses[2], stockStatuses[2]],
[stockStatuses[3], stockStatuses[3]],
[stockStatuses[4], stockStatuses[4]],
],
colHeaders: ['allowHtml: false (default)', 'allowHtml: true'],
columns: [
{
type: 'autocomplete',
source: stockStatuses,
strict: false,
// allowHtml: false is the default — HTML tags in `source` are shown as plain text
},
{
type: 'autocomplete',
source: stockStatuses,
strict: false,
// render `source` values as HTML — only use with trusted, static data
allowHtml: true,
},
],
// licenseKey: 'your-license-key', // get a key at https://handsontable.com/pricing/
});
</script>
<template>
<div id="example9">
<HotTable :settings="hotSettings" />
</div>
</template>

Result

After configuring the autocomplete cell type, cells display a text input that shows matching suggestions as the user types. In strict mode, only values from the source list are accepted. In flexible mode, users can also enter custom values not in the list.

Keyboard shortcuts

The autocomplete cell editor shares its keyboard shortcuts with the handsontable editor. In strict mode, a few of these shortcuts behave differently — see Autocomplete strict mode.

Related guides

Configuration options

Core methods

Hooks