External search box
In this tutorial, you will add a search input outside Handsontable that highlights matching cells as you type. You will learn how to use the Search plugin’s query() method and hot.render() to apply real-time cell highlights from an external control.
Enable the Search plugin
Set
search: truein grid settings:const hot = new Handsontable(container, {data,search: true,licenseKey: 'non-commercial-and-evaluation',});This enables the plugin and the default
htSearchResulthighlight class.Add an external input
Render a text input above the grid container:
const controls = document.createElement('div');const searchInput = document.createElement('input');searchInput.type = 'search';searchInput.placeholder = 'Search in table...';controls.appendChild(searchInput);container.parentElement?.insertBefore(controls, container);The input lives outside Handsontable, so you can style and place it like any other app control.
Bind the input to
query()Listen to input events, query the plugin, and re-render:
const searchPlugin = hot.getPlugin('search');searchInput.addEventListener('input', () => {searchPlugin.query(searchInput.value);hot.render();});query()updates each cell’sisSearchResultmetadata.hot.render()applies the updated highlight state.
Step 4 (optional): Debounce for large datasets
If you search very large tables, debounce the input callback to reduce render frequency:
function debounce<T extends (...args: any[]) => void>(callback: T, wait = 120) { let timeoutId: ReturnType<typeof setTimeout> | undefined;
return (...args: Parameters<T>) => { clearTimeout(timeoutId); timeoutId = setTimeout(() => callback(...args), wait); };}Use this wrapper around your search handler when needed.
What you learned
- How to enable the
Searchplugin withsearch: truein Handsontable settings. - How to place a search input outside the grid and call
hot.getPlugin('search').query(value)on every input event. - Why you must call
hot.render()afterquery()to apply the updatedisSearchResultmetadata to cells. - How to add debouncing to limit render frequency when searching large datasets.
Next steps
- Explore highlight search matches to wrap matched text in
<mark>tags instead of using the default cell highlight class. - Add multi-column filtering to let users filter by multiple columns at once through an external panel.