Column filter
Filter data by values or by a set of conditions, using Handsontable’s intuitive user interface or flexible API.
Overview
Filtering lets you quickly find the information that you’re looking for, based on specific criteria. This makes data analysis easier and faster, especially with large data sets.
Handsontable’s built-in filtering interface resembles Excel’s, so it’s intuitive even to non-technical users. And if you want to implement your own interface, you can easily filter data programmatically, using Handsontable’s API.
You can filter data by value, or use the built-in conditions, which are different for each of the available column types.
Filtering demo
Click on one of the column menu buttons (▼) and play around with filtering by selecting values or conditions-based criteria.
After filtering, the column readjusts its width to the longest value displayed on screen. To disable this behavior, set fixed column widths.
// to import filtering as an individual module, see the 'Import the filtering module' section of this pageimport Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterBasicDemo');
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});// to import filtering as an individual module, see the 'Import the filtering module' section of this pageimport Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterBasicDemo')!;
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});<div id="exampleFilterBasicDemo"></div>Enable filtering
To enable the filtering interface for all columns, you need to do two things:
- Set the
filtersoption totrue. - Enable the interface by setting the
dropdownMenuoption totrue.
Enabling the filters option without the interface can be useful if you plan to create your own
custom interface for filtering by using the API.
const configurationOptions = { // enable filtering filters: true, // enable the column menu dropdownMenu: true,};
By default, the column menu presents the filtering interface along with other default items such as Insert column left. To display only the filtering interface, pass an array of filter items in the configuration.
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleShowFilterItemsOnly');
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu, but display only the filter menu items dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'], height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleShowFilterItemsOnly')!;
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu, but display only the filter menu items dropdownMenu: ['filter_by_condition', 'filter_by_value', 'filter_action_bar'], height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});<div id="exampleShowFilterItemsOnly"></div>Enable filtering for individual columns
You have control over which columns are filterable and for which columns the column menu is enabled. In the following demo, only the Brand column is filterable, while the other columns are not. However, the Model column still has the column menu available in case you want to have some useful items in the menu such as Clear column.
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleEnableFilterInColumns');
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering for all columns filters: true, // enable the column menu for all columns // but display only the 'Filter by value' list and the 'OK' and 'Cancel' buttons dropdownMenu: { items: { filter_by_value: { // hide the 'Filter by value' list from all columns but the first one hidden() { return this.getSelectedRangeLast().to.col > 0; }, }, filter_action_bar: { // hide the 'OK' and 'Cancel' buttons from all columns but the first one hidden() { return this.getSelectedRangeLast().to.col > 0; }, }, clear_column: { // hide the 'Clear column' menu item from the first column hidden() { return this.getSelectedRangeLast().to.col < 1; }, }, }, }, // `afterGetColHeader()` is a Handsontable hook // it's fired after Handsontable appends information about a column header to the table header afterGetColHeader(col, TH) { // remove the column menu button from the 'Brand', 'Price', and 'Date' columns if (col > 1) { const button = TH.querySelector('.changeType');
if (!button) { return; }
button.parentElement.removeChild(button); } }, height: 'auto', example: 'exampleEnableFilterInColumns', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleEnableFilterInColumns')!;
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering for all columns filters: true, // enable the column menu for all columns // but display only the 'Filter by value' list and the 'OK' and 'Cancel' buttons dropdownMenu: { items: { filter_by_value: { // hide the 'Filter by value' list from all columns but the first one hidden() { return this.getSelectedRangeLast()!.to.col > 0; }, }, filter_action_bar: { // hide the 'OK' and 'Cancel' buttons from all columns but the first one hidden() { return this.getSelectedRangeLast()!.to.col > 0; }, }, clear_column: { // hide the 'Clear column' menu item from the first column hidden() { return this.getSelectedRangeLast()!.to.col < 1; }, }, }, }, // `afterGetColHeader()` is a Handsontable hook // it's fired after Handsontable appends information about a column header to the table header afterGetColHeader(col, TH) { // remove the column menu button from the 'Brand', 'Price', and 'Date' columns if (col > 1) { const button = TH.querySelector('.changeType')!;
if (!button) { return; }
button.parentElement!.removeChild(button); } }, height: 'auto', example: 'exampleEnableFilterInColumns', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',} as Handsontable.GridSettings);<div id="exampleEnableFilterInColumns"></div>Enable filtering within already filtered results
To apply filters based on the search input, set searchMode to 'apply'. You can then apply the filter by either pressing the Enter key while the search input is focused or by clicking the OK button.
const configurationOptions = { // enable filtering filters: { searchMode: 'apply' }, // enable the column menu dropdownMenu: true,};import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleSearchMode');
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering with option filters: { searchMode: 'apply', }, dropdownMenu: true, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleSearchMode')!;
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering with option filters: { searchMode: 'apply', }, dropdownMenu: true, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});<div id="exampleSearchMode"></div>Filter different types of data
With its built-in cell types, Handsontable makes it easy to handle common data types like text, numbers, and dates by providing numerous configuration options. In addition, the filtering feature is designed to understand the underlying data and provides an adaptive interface that is tailored to each data type.
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterDifferentTypes');
new Handsontable(container, { data: [ { model: 'Racing Socks', size: 'S', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, color: 'Black', }, { model: 'HL Mountain Shirt', size: 'XS', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, color: 'White', }, { model: 'Cycling Cap', size: 'L', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, color: 'Green', }, { model: 'Ski Jacket', size: 'M', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, color: 'Blue', }, { model: 'HL Goggles', size: 'XL', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, color: 'Black', }, ], columns: [ { title: 'Model', // set the type of the 'Model' column type: 'text', data: 'model', }, { title: 'Price', // set the type of the 'Price' column type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Sold on', // set the type of the 'Date' column type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', // set the type of the 'Time' column type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', // set the type of the 'In stock' column type: 'checkbox', data: 'inStock', className: 'htCenter', }, { title: 'Size', // set the type of the 'Size' column type: 'dropdown', data: 'size', source: ['XS', 'S', 'M', 'L', 'XL'], className: 'htCenter', }, { title: 'Color', // set the type of the 'Size' column type: 'autocomplete', data: 'color', source: ['White', 'Black', 'Yellow', 'Blue', 'Green'], className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, height: 175, autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterDifferentTypes')!;
new Handsontable(container, { data: [ { model: 'Racing Socks', size: 'S', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, color: 'Black', }, { model: 'HL Mountain Shirt', size: 'XS', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, color: 'White', }, { model: 'Cycling Cap', size: 'L', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, color: 'Green', }, { model: 'Ski Jacket', size: 'M', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, color: 'Blue', }, { model: 'HL Goggles', size: 'XL', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, color: 'Black', }, ], columns: [ { title: 'Model', // set the type of the 'Model' column type: 'text', // 'text' is the default type, so you can omit this line data: 'model', }, { title: 'Price', // set the type of the 'Price' column type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Sold on', // set the type of the 'Date' column type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', // set the type of the 'Time' column type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', // set the type of the 'In stock' column type: 'checkbox', data: 'inStock', className: 'htCenter', }, { title: 'Size', // set the type of the 'Size' column type: 'dropdown', data: 'size', source: ['XS', 'S', 'M', 'L', 'XL'], className: 'htCenter', }, { title: 'Color', // set the type of the 'Size' column type: 'autocomplete', data: 'color', source: ['White', 'Black', 'Yellow', 'Blue', 'Green'], className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, height: 175, autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});<div id="exampleFilterDifferentTypes"></div>The following table contains all available filter operators for each built-in data type.
| Cell type | Available filter operators |
|---|---|
| All cell types | Default operators: None Is empty Is not empty Is equal to Is not equal to |
| text time checkbox dropdown autocomplete password | Default operators plus: Begins with Ends with Contains Does not contain |
| numeric | Default operators plus: Greater than Greater than or equal to Less than Less than or equal to Is between Is not between |
| date | Default operators plus: Before After Is between Tomorrow Today Yesterday |
Filter data on initialization
You can filter data on Handsontable’s initialization. This lets you apply pre-defined filters every time you launch your grid.
To do this, you can use Handsontable’s afterInit() hook, along with
the API provided by the Filters plugin. For instance, the demo below demonstrates how you can start
with a pre-applied filter to display only items priced less than $200.
import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterOnInitialization');
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, // `afterInit()` is a Handsontable hook: it's fired after the Handsontable instance is initiated afterInit() { const handsontableInstance = this; // get the `Filters` plugin, so you can use its API const filters = handsontableInstance.getPlugin('filters');
// filter data by the 'Price' column (column at index 2) // to display only items that are less than ('lt') $200 filters.addCondition(2, 'lt', [200]); filters.filter(); }, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});import Handsontable from 'handsontable/base';import { registerAllModules } from 'handsontable/registry';import { Filters } from 'handsontable/plugins';
// Register all Handsontable's modules.registerAllModules();
const container = document.querySelector('#exampleFilterOnInitialization')!;
new Handsontable(container, { data: [ { brand: 'Jetpulse', model: 'Racing Socks', price: 30, sellDate: '2023-10-11', sellTime: '01:23', inStock: false, }, { brand: 'Gigabox', model: 'HL Mountain Frame', price: 1890.9, sellDate: '2023-05-03', sellTime: '11:27', inStock: false, }, { brand: 'Camido', model: 'Cycling Cap', price: 130.1, sellDate: '2023-03-27', sellTime: '03:17', inStock: true, }, { brand: 'Chatterpoint', model: 'Road Tire Tube', price: 59, sellDate: '2023-08-28', sellTime: '08:01', inStock: true, }, { brand: 'Eidel', model: 'HL Road Tire', price: 279.99, sellDate: '2023-10-02', sellTime: '01:23', inStock: true, }, ], columns: [ { title: 'Brand', type: 'text', data: 'brand', }, { title: 'Model', type: 'text', data: 'model', }, { title: 'Price', type: 'numeric', data: 'price', locale: 'en-US', numericFormat: { style: 'currency', currency: 'USD', minimumFractionDigits: 2, }, }, { title: 'Date', type: 'intl-date', data: 'sellDate', locale: 'en-US', dateFormat: { month: 'short', day: 'numeric', year: 'numeric' }, className: 'htRight', }, { title: 'Time', type: 'intl-time', data: 'sellTime', locale: 'en-US', timeFormat: { hour: '2-digit', minute: '2-digit', hour12: true }, className: 'htRight', }, { title: 'In stock', type: 'checkbox', data: 'inStock', className: 'htCenter', }, ], // enable filtering filters: true, // enable the column menu dropdownMenu: true, // `afterInit()` is a Handsontable hook: it's fired after the Handsontable instance is initiated afterInit() { const handsontableInstance = this; // get the `Filters` plugin, so you can use its API const filters: Filters = handsontableInstance.getPlugin('filters');
// filter data by the 'Price' column (column at index 2) // to display only items that are less than ('lt') $200 filters.addCondition(2, 'lt', [200]); filters.filter(); }, height: 'auto', autoWrapRow: true, autoWrapCol: true, licenseKey: 'non-commercial-and-evaluation',});<div id="exampleFilterOnInitialization"></div>External quick filter
Handsontable’s quick filter feature lets you search for a particular phrase in a specific column. To
accomplish this, use methods filters.addCondition() and
filters.filter().