Filtering
Filter rows with floating filters and their expression syntax, typed filter models for text, number, date, set and boolean columns, a quick filter and custom predicates.
Birch UI Grid filters rows in three complementary ways, and all of them combine with AND:
- Column filters, one
FilterModelper column, set from floating filters in the header or from code. - The quick filter, one search string matched against every visible column.
- Custom filters, a predicate function you supply as a filter model.
Filtering runs before sorting and pagination, on raw values, never on formatted text.
Loading demo…
View source
Sample data and small UI helpers are imported from the docs' demos/_shared.ts and demos/_scheduler-data.ts files.
import { createGrid, type ColumnDef } from '@birchui/core';
import {
docsTheme,
field,
formatCurrency,
layout,
makeOrders,
onDocsThemeChange,
revenueOf,
type Order,
} from './_shared';
export const meta = { title: 'Sorting, floating filters and quick filter', height: 480 };
const columns: ColumnDef<Order>[] = [
{ field: 'id', header: 'Order', width: 110 },
{ field: 'customer', header: 'Customer', flex: 1, minWidth: 150 },
{ field: 'region', header: 'Region', width: 130, filter: 'set' },
{ field: 'status', header: 'Status', width: 116, filter: 'set' },
{ id: 'revenue', header: 'Revenue', type: 'number', width: 120, valueGetter: revenueOf, format: formatCurrency },
{ field: 'orderDate', header: 'Ordered', type: 'date', width: 120 },
];
export default function mount(el: HTMLElement): () => void {
const { toolbar, body, status } = layout(el);
const search = document.createElement('input');
search.type = 'search';
search.placeholder = 'Customer, product, rep…';
toolbar.append(field('Quick filter', search), 'Shift+click a header to add a sort level. Try >5000 in Revenue.');
const grid = createGrid<Order>(body, {
columns,
rows: makeOrders(2000),
getRowId: (order) => order.id,
defaultColumn: { sortable: true, filter: true },
floatingFilters: true,
multiSort: true,
sort: [{ colId: 'revenue', dir: 'desc' }],
theme: docsTheme(),
ariaLabel: 'Orders with sorting and filtering',
});
const describe = () => {
const sort =
grid
.getSort()
.map((s) => `${s.colId} ${s.dir}`)
.join(', ') || 'none';
const filters = Object.keys(grid.getFilterModel()).join(', ') || 'none';
const shown = grid.getDisplayRows().length;
status.textContent = `${shown.toLocaleString()} of ${grid.getRows().length.toLocaleString()} orders. Sort: ${sort}. Filters: ${filters}.`;
};
const onInput = () => grid.setQuickFilter(search.value);
search.addEventListener('input', onInput);
const offs = [
grid.on('modelUpdated', describe),
grid.on('sortChanged', describe),
grid.on('filterChanged', describe),
];
const stopTheme = onDocsThemeChange((theme) => grid.update({ theme }));
describe();
return () => {
search.removeEventListener('input', onInput);
for (const off of offs) off();
stopTheme();
grid.destroy();
};
}Enabling filters#
Mark columns as filterable with filter, and turn on the filter row under the headers with floatingFilters:
import { createGrid, type ColumnDef } from '@birchui/core';
const columns: ColumnDef<Order>[] = [
{ field: 'id', header: 'Order', filter: 'text' },
{ field: 'customer', flex: 1, filter: true },
{ field: 'region', filter: 'set', options: ['EMEA', 'North America', 'APAC', 'LATAM'] },
{ field: 'orderDate', header: 'Ordered', type: 'date', filter: true },
{ field: 'revenue', type: 'number', filter: true },
{ field: 'priority', type: 'boolean', filter: true },
];
const grid = createGrid<Order>(document.querySelector('#orders')!, {
columns,
rows: orders,
getRowId: (o) => o.id,
floatingFilters: true,
});filter: true chooses the filter from the column:
| Column | Filter kind |
|---|---|
Has options |
set |
type: 'number' |
number |
type: 'date' |
date |
type: 'boolean' |
boolean |
| Anything else | text |
Pass a kind explicitly ('text', 'number', 'date', 'set' or 'boolean') to override the choice. defaultColumn: { filter: true } makes every column filterable.
Floating filters#
With floatingFilters: true the header gets a second row with one filter control per filterable column:
- Text, number and date columns get a text box. Users type a short expression (below) and the grid applies it 200 ms after they stop typing. The placeholder hints at the syntax:
>100, 10..20for numbers and>2026-01-01for dates. An empty box clears the column's filter. - Set and boolean columns get a dropdown. Boolean columns offer All, Yes and No. Set columns list the column's
options, or, without options, up to 200 distinct values found in the data, sorted naturally. Choosing All clears the filter.
Keyboard users reach the filter row by pressing Arrow Down on a header, and leave it with Arrow Down (to the first row) or Arrow Up (back to the header). A header whose column is filtered shows a dotted underline under its label.
Floating filter syntax#
The text box understands the same expressions as parseFilterInput(kind, text), which @birchui/core exports so you can reuse the syntax in your own search fields.
Number columns#
| Input | Meaning | Filter model |
|---|---|---|
250 or =250 or ==250 |
Equal to 250 | { type: 'number', op: 'eq', value: 250 } |
!=0 or <>0 |
Not equal to 0 | { op: 'ne', value: 0 } |
>100 |
Greater than 100 | { op: 'gt', value: 100 } |
>=100 |
At least 100 | { op: 'gte', value: 100 } |
<50 |
Less than 50 | { op: 'lt', value: 50 } |
<=50 |
At most 50 | { op: 'lte', value: 50 } |
10..20, 10 to 20 or 10–20 |
Between 10 and 20, inclusive | { op: 'between', value: 10, valueTo: 20 } |
blank or (blank) |
Empty cells | { op: 'blank' } |
!blank or (not blank) |
Non-empty cells | { op: 'notBlank' } |
Numbers may include thousands separators, so >12,500 works. A range can be typed in either order: 20..10 matches the same rows as 10..20.
Date columns#
| Input | Meaning | Filter model |
|---|---|---|
2026-03-15 or =2026-03-15 |
On that day | { type: 'date', op: 'eq', value: '2026-03-15' } |
<2026-03-15 |
Before that day | { op: 'before', value: '2026-03-15' } |
>2026-03-15 |
After that day | { op: 'after', value: '2026-03-15' } |
2026-01-01..2026-03-31 or 2026-01-01 to 2026-03-31 |
Between two days, inclusive | { op: 'between', value: '2026-01-01', valueTo: '2026-03-31' } |
blank / !blank |
Empty or non-empty | { op: 'blank' } / { op: 'notBlank' } |
Date filters compare calendar days in local time, ignoring the time of day. <= and >= are accepted and behave like < and >; use a range when you need an inclusive bound.
Text columns#
| Input | Meaning | Filter model op |
|---|---|---|
harbor |
Contains "harbor" | contains |
!harbor |
Does not contain "harbor" | notContains |
=Northwind Traders |
Equals, ignoring case | equals |
!=Northwind Traders |
Does not equal | notEquals |
^North |
Starts with | startsWith |
Foods$ |
Ends with | endsWith |
blank / !blank |
Empty or non-empty | blank / notBlank |
Text matching is always case-insensitive.
Set and boolean values#
parseFilterInput('set', 'EMEA, APAC') returns { type: 'set', values: ['EMEA', 'APAC'] }, and parseFilterInput('boolean', 'yes') returns { type: 'boolean', value: true }. Booleans accept yes, true, y, 1, on or x for true and no, false, n, 0 or off for false. The floating filter UI uses dropdowns for these kinds, so this syntax matters when you build your own inputs:
import { parseFilterInput } from '@birchui/core';
regionSearch.addEventListener('change', () => {
grid.setFilter('region', parseFilterInput('set', regionSearch.value));
});parseFilterInput() returns null for empty or unparseable input, which setFilter() treats as "remove this filter".
Filter popup#
Every filterable column gets a Filter… item in its column menu. Ctrl+Shift+F (⌘+Shift+F on macOS) on a focused header or cell opens the same dialog for that column. It works with or without floating filters.
| Filter kind | Controls |
|---|---|
text |
Two conditions (contains, does not contain, equals, does not equal, starts with, ends with, blank, not blank) joined by AND or OR |
number, date |
The same, with Between taking a from and a to value |
set |
A searchable checklist with row counts and Select all. Values come from the column's options, or from the rows when it has none. Lists longer than 500 values are virtualized |
boolean |
All, Yes or No |
Apply (or Enter) sets the filter, Reset clears it, and Close (or Escape) leaves it as it was. Focus stays inside the dialog while it is open and returns to the column header when it closes. Invalid input, such as a missing second value for Between, is reported inside the dialog and nothing is applied.
Two conditions are stored as a combined model, which you can also set from code:
grid.setFilter('total', {
type: 'combined',
op: 'or',
conditions: [
{ type: 'number', op: 'lt', value: 100 },
{ type: 'number', op: 'gt', value: 10000 },
],
});The floating filter shows and accepts the same filter as <100 OR >10000. AND binds more tightly than OR. Every label in the dialog can be translated; see Localization.
Filter models#
The filter state is a record from column ID to FilterModel. You can set it up front with filterModel, change it with the API and read it back to persist it.
Text#
{ type: 'text', op: 'contains', value: 'logistics' }op is one of contains, notContains, equals, notEquals, startsWith, endsWith, blank and notBlank. Values are compared as lowercase strings; blank cells count as an empty string, so notContains keeps them.
Number#
{ type: 'number', op: 'between', value: 1000, valueTo: 5000 }op is one of eq, ne, lt, lte, gt, gte, between, blank and notBlank. lt, lte, gt, gte and between never match blank cells. ne keeps blank cells, since a blank is not equal to the value.
Date#
{ type: 'date', op: 'after', value: '2026-01-31' }
{ type: 'date', op: 'between', value: new Date(2026, 0, 1), valueTo: new Date(2026, 2, 31) }op is one of eq, before, after, between, blank and notBlank. value and valueTo accept a Date, epoch milliseconds or a date string.
Set#
{ type: 'set', values: ['EMEA', 'APAC'] }Keeps rows whose value is strictly equal to one of values. Date values are compared by timestamp.
Boolean#
{ type: 'boolean', value: true }Truthy strings such as "yes" and numbers other than 0 count as true. Blank cells count as false.
Custom#
{ type: 'custom', test: (value, row) => boolean }See Custom filters.
Filtering from code#
grid.setFilter('region', { type: 'set', values: ['EMEA'] });
grid.setFilter('revenue', { type: 'number', op: 'gte', value: 10000 });
grid.setFilter('region', null);
grid.setFilterModel({
status: { type: 'text', op: 'notEquals', value: 'Cancelled' },
orderDate: { type: 'date', op: 'between', value: '2026-01-01', valueTo: '2026-03-31' },
});
const model = grid.getFilterModel();setFilter(colId, null) removes one column's filter. setFilterModel({}) clears all column filters. Entries for columns that do not exist are ignored. The initial filterModel option and update({ filterModel }) behave like setFilterModel(). Every filter change, from the UI, these methods or update({ filterModel }) and update({ quickFilter }), fires filterChanged and returns a paginated grid to its first page.
Quick filter#
The quick filter searches every visible column at once, the way a search box above a table usually does.
const search = document.querySelector<HTMLInputElement>('#order-search')!;
search.addEventListener('input', () => grid.setQuickFilter(search.value));Or set it as an option: createGrid(container, { quickFilter: 'harbor' }) or grid.update({ quickFilter: '' }).
How it matches:
- The text is split on whitespace and every term must match, in any column.
harbor pendingfinds Blue Harbor Foods orders that are pending. - Matching is case-insensitive and finds substrings.
- Each column contributes its formatted text when it has a
formatfunction, otherwise its raw value as a string. A revenue column formatted as$18,400.00matches18,400. - Every column you defined is searched, including hidden ones, so users can find rows by a value they cannot see, such as an internal account code. Generated columns, like the selection checkbox column, are skipped. To keep a column out of the quick filter, leave it out of
columnsand read the value in avalueGetteror renderer instead.
The grid caches the searchable text of each row and rebuilds it when rows change, so typing stays fast on large datasets.
Custom filters#
A custom filter model carries a predicate. It receives the column value and the row and returns true to keep the row.
const today = new Date();
grid.setFilter('due', {
type: 'custom',
test: (value, row) => !row.paid && new Date(String(value)) < today,
});A custom filter can also express conditions across columns. Attach it to the column the user would expect to see it on:
grid.setFilter('customer', {
type: 'custom',
test: (_value, row) => row.region === 'EMEA' && row.revenue > 20000,
});Reacting to filter changes#
filterChanged fires when a column filter or the quick filter changes, from the UI or from code:
grid.on('filterChanged', ({ filterModel, quickFilter }) => {
const serializable = Object.fromEntries(Object.entries(filterModel).filter(([, m]) => m.type !== 'custom'));
const params = new URLSearchParams({ q: quickFilter, filters: JSON.stringify(serializable) });
history.replaceState(null, '', `?${params}`);
});
grid.on('modelUpdated', ({ rowCount, displayRowCount }) => {
counter.textContent = `Showing ${displayRowCount} of ${rowCount} orders`;
});Related#
- Sorting runs after filtering.
- Tree data keeps the ancestors of matching rows visible.
- Events reference lists every payload.