Sorting and filtering
Click a header to sort. Filter through the API (setFilterModel), or turn on the filterRow option to put an input under each header (Header filter row). The name and department inputs in the demo below are example UI that calls setFilterModel.
Sort by header click
No setup is needed. Each click cycles through ascending, descending and off. Shift+click keeps the existing sort and adds one more key; the header then shows a priority number.
Set sortable: false on a column you do not want sorted. Clicking it does nothing. The header cell's aria-sort carries the direction; the priority number is visual only.
Sort from code
The first entry has the highest priority.
api.setSortModel([
{ columnId: 'salary', direction: 'desc' },
{ columnId: 'name', direction: 'asc' },
]);
api.getSortModel(); // a copy of the current model
api.setSortModel([]); // clearChange how sorting works
Since 1.3.4
sortCycle, sortCollator, multiSort, showUnsortedIcon and the column options compare, sortBy, sortCycle are available from 1.3.4. Without them everything behaves as before.
createGrid(el, {
columns: [
{ id: 'name', sortBy: 'text' }, // sort by the displayed text (formatValue result)
{ id: 'grade', compare: (a, b) => rank(a) - rank(b) }, // your own comparator
{ id: 'amount', kind: 'number', sortCycle: ['desc', 'asc'] }, // a cycle for this column only
],
rows,
sortCycle: ['asc', 'desc'], // default is ['asc', 'desc', 'none']
sortCollator: { caseFirst: 'upper', sensitivity: 'variant' },
multiSort: 'ctrl', // 'shift' (default) | 'ctrl' | 'always' | 'off'
showUnsortedIcon: true, // muted icon on sortable unsorted headers
});| Option | Meaning |
|---|---|
sortCycle | Order of states a header click goes through: one or more of asc, desc, none, no duplicates. A column sortCycle wins |
sortCollator | String ordering rules: locale and Intl.Collator options. numeric: true stays on unless you turn it off |
multiSort | How several columns are sorted: shift (Shift+click), ctrl (Ctrl or Cmd+click), always (every click adds), off (one column only) |
showUnsortedIcon | A muted up-down arrow on sortable headers that are not sorted. No aria-sort is added |
compare(a, b, rowA, rowB) | Comparator for ascending order; descending negates it. Empty values are passed as they are |
sortBy | 'value' (default) or 'text' (compare the displayed text with the collator) |
compareis calledO(n log n)times per sort. Values and rows are collected up front, but a heavy function is slow on big data. If it throws it counts as equal (order kept) and oneerrorevent (callback-error) per column is emitted per sort.- With
compareset, the comparator also decides where empty values go (the rule "empty values last" applies to the default ordering only). - In server paging (
pagination.mode: 'server')compareis not used, because the server sorts. Oneerrorevent (invalid-option) per column says so. - Pinned rows stay out of sorting as before (
pinnedRows.sortsorts them among themselves). api.getSortCollator()returns the collator in use; it is the same object while the options stay the same.
How sort order is decided
- Empty values always go last, in either direction. Empty means
null,undefined,'',NaNand dates that cannot be parsed. Switching to descending does not move empty rows to the top. - Equal values keep their original order. Descending does not reverse them.
- Strings sort with Korean collation (
Intl.Collator('ko', { numeric: true })), and digits inside text compare as numbers:item2comes beforeitem10. For Korean, this means Hangul syllables sort in the usual 가나다 order. Whether Hangul or Latin letters come first depends on the browser's ICU data, so do not rely on it. - In a number column, numbers come first, then text such as
'abc', then empty values. - The sort key is the value
getValuereturns. IfformatValueshows$84,000, the sort still uses the number.
Date columns compare calendar dates in the local time zone, not instants. In Korea, new Date(2024, 0, 1) shows as 2024-01-01 and sorts as that day; in Los Angeles the same code gives the same local day. Two times on the same day count as equal. If you need time-of-day ordering, store epoch milliseconds in a number column.
Filter rows
match: 'all' keeps rows that satisfy every condition, and 'any' keeps rows that satisfy at least one. With no conditions, every row is visible.
api.setFilterModel({
match: 'all',
items: [
{ columnId: 'department', operator: 'equals', value: 'Engineering' },
{ columnId: 'salary', operator: 'between', value: [70_000, 90_000] },
],
});
api.getFilterModel(); // a copy of the current model
api.setFilterModel(null); // clearThe operators you can use depend on the column kind. isEmpty and isNotEmpty work on every kind.
| kind | Operators |
|---|---|
text, select, custom, omitted | contains equals notEquals startsWith endsWith in |
number, date | equals notEquals gt gte lt lte between in |
boolean | equals notEquals |
- Text comparison ignores case and treats composed and decomposed Hangul as the same letters. The search term is matched literally; regular expressions are not supported.
betweenincludes both ends, and[from, to]in reverse order gives the same result.inis an exact, case-sensitive match.- A number column treats numbers,
bigintand numeric strings such as'12.5'as numbers.'1,200'is not a number. - In number, date and boolean columns, empty values match only
isEmpty,notEqualsandin(when the list containsnull). They never matchequals,gtorbetween. - A date filter value such as
'2024-01-31'means that local day. A date that does not exist, such as'2024-02-30', throwsinvalid-option.
Quick filter and external filter
A quick filter finds rows from one piece of text across several columns, and an external filter is decided by your app (1.3.6). Both combine with the column filter (filterModel) by AND.
api.setQuickFilter('red seoul'); // every word must be in some column
api.setQuickFilter('apple pear', { match: 'any', columns: ['name'] });
api.getQuickFilter(); // { text, columns, split, match, includeHidden, caseSensitive } or null
api.resetQuickFilter();| Option | Meaning | Default |
|---|---|---|
text | The text to find (only in the quickFilter option) | none |
columns | Column ids to search | All visible columns |
split | Split into words by whitespace and find each | true |
match | 'all' every word, 'any' at least one | 'all' |
includeHidden | Search hidden columns too | false |
caseSensitive | Match case | false |
- It searches the text the cell shows (after
formatValue). Empty text does nothing, and thequickFilterChanged { text }event fires on a change. - In a tree the ancestors of matching rows stay, and totals and page counts use the filtered rows.
- It is not part of
getViewState()(only the filter model is saved). With server paging the grid does not filter; it sendsquickFilter { text, columns, match }in theloadPagerequest. - When no visible row is left, a
noMatchesevent fires once.
The external filter keeps the rows for which externalFilter(row, rowKey) returns true. Call refreshFilter() to recompute after the values it reads change. If the callback throws, that row stays and one callback-error is reported per pass. With server paging a function cannot be sent to the server, so it is an invalid-option.
createGrid(el, { columns, rows, externalFilter: (row) => row.price >= minPrice });
minPrice = 1000;
api.refreshFilter();Read the visible rows
The rows left after filtering and sorting are the visible rows. The original rows (getRows()) stay untouched.
| Method | Behavior |
|---|---|
getVisibleRowCount() | Number of visible rows |
getVisibleRows() | Array of visible rows, in screen order |
getRowAtVisibleIndex(i) | The row on screen line i; undefined when out of range |
getVisibleIndexOfKey(key) | Screen line of a row key; -1 if hidden by a filter or missing |
scrollToRow(key) | Scrolls the minimum distance and returns true, or false if the row is not visible |
The rowIndex in events such as rowClicked is the screen line number. It is not an index into your original array; use row or rowKey from the payload when you need the original row. When rows are added, updated or removed, the visible rows are recomputed with the current sort and filter.
Hide rows without a filter
To drop chosen rows without a condition use hideRows. It moves independently of the filter and you read it with isRowHidden. See Hide and show rows for the rules.
grouping.hideRows (1.4.0) is a different feature: it stops drawing the group header lines and does not hide data rows.
Block a change before it happens
When hooks.beforeSort or hooks.beforeFilter returns false, the sort or filter does not change. Use it, for example, to block sorting while there are unsaved edits. The rules are in the hooks table.
Events
sortChanged and filterChanged fire once, after the model actually changes. Setting the same model again fires nothing. When a column change drops an entry from the model, the event fires.
api.on('sortChanged', ({ sortModel }) => console.log(sortModel));
api.on('filterChanged', ({ filterModel }) => console.log(filterModel));You can call setSortModel and other API methods inside a handler. Events raised inside a handler are delivered in order after the current event finishes.
Connect a search box
For inputs under the headers, turn on filterRow: true; the rule in this section (filter while composing) is already applied. For a search box or filter input you build yourself, connect it like this.
Read event.target.value in the input event and call setFilterModel. The event also fires while an IME is composing (for example a Korean syllable that is not finished), so the filter follows the text as it is typed. Do not wait for composition to end. If typing is fast, add a debounce of 100 to 150 ms and apply only the last value.
input.addEventListener('input', (event) => {
const text = (event.target as HTMLInputElement).value.trim();
api.setFilterModel(
text
? { match: 'all', items: [{ columnId: 'name', operator: 'contains', value: text }] }
: null,
);
});React reads the same value in onChange and Angular in (input). In Vue, use :value and read $event.target.value in @input instead of v-model. v-model updates its value only after composition ends, so a handler that reads it is one character behind.
Do not filter only on change or keyup, and do not skip the event when isComposing is true. Ignoring Enter during composition applies to confirming a cell edit only.
Performance
These numbers come from createGridCore with 100,000 rows. They are medians of 7 runs after warm-up of the 1.3.2 build on an Intel Core Ultra 5 250K Plus (18 threads), Linux, Node 24 (measured 2026-11-13) and will differ on other machines. The method and a script you can run yourself are on How we measured performance.
| Operation | Time |
|---|---|
| Sort by one number column | about 24ms |
| Sort by one Korean text column (about 200 unique values) | about 24ms |
Number between filter | about 3ms |
| Add one row while sorted, then recompute | about 34ms |
Text columns with very many unique values are slow. Sorting a Korean column with 100,000 unique values took about 0.14 seconds (140 ms) in the same environment, mostly the cost of Intl.Collator. For such columns, setting sortable: false is the practical option today.
What the filter sees
Use a column's filterValue to make the filter and the value list look at something other than getValue, and valueKey to treat object values as the same value. Sorting still looks at getValue. Details are in Header filter row.
Invalid models
A column that does not exist, a column with sortable: false or filterable: false, an operator that the column kind does not support, or a value that cannot be parsed throws GridError('invalid-option'). The call fails before it changes any state, so the existing sort and filter stay as they were.