Skip to content

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.

Live demo — drawn by the real renderer

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.

ts
api.setSortModel([
  { columnId: 'salary', direction: 'desc' },
  { columnId: 'name', direction: 'asc' },
]);

api.getSortModel(); // a copy of the current model
api.setSortModel([]); // clear

Change 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.

ts
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
});
OptionMeaning
sortCycleOrder of states a header click goes through: one or more of asc, desc, none, no duplicates. A column sortCycle wins
sortCollatorString ordering rules: locale and Intl.Collator options. numeric: true stays on unless you turn it off
multiSortHow several columns are sorted: shift (Shift+click), ctrl (Ctrl or Cmd+click), always (every click adds), off (one column only)
showUnsortedIconA 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)
  • compare is called O(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 one error event (callback-error) per column is emitted per sort.
  • With compare set, 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') compare is not used, because the server sorts. One error event (invalid-option) per column says so.
  • Pinned rows stay out of sorting as before (pinnedRows.sort sorts 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, '', NaN and 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: item2 comes before item10. 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 getValue returns. If formatValue shows $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.

ts
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); // clear

The operators you can use depend on the column kind. isEmpty and isNotEmpty work on every kind.

kindOperators
text, select, custom, omittedcontains equals notEquals startsWith endsWith in
number, dateequals notEquals gt gte lt lte between in
booleanequals 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.
  • between includes both ends, and [from, to] in reverse order gives the same result.
  • in is an exact, case-sensitive match.
  • A number column treats numbers, bigint and 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, notEquals and in (when the list contains null). They never match equals, gt or between.
  • A date filter value such as '2024-01-31' means that local day. A date that does not exist, such as '2024-02-30', throws invalid-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.

ts
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();
OptionMeaningDefault
textThe text to find (only in the quickFilter option)none
columnsColumn ids to searchAll visible columns
splitSplit into words by whitespace and find eachtrue
match'all' every word, 'any' at least one'all'
includeHiddenSearch hidden columns toofalse
caseSensitiveMatch casefalse
  • It searches the text the cell shows (after formatValue). Empty text does nothing, and the quickFilterChanged { 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 sends quickFilter { text, columns, match } in the loadPage request.
  • When no visible row is left, a noMatches event 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.

ts
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.

MethodBehavior
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.

ts
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.

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.

ts
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.

OperationTime
Sort by one number columnabout 24ms
Sort by one Korean text column (about 200 unique values)about 24ms
Number between filterabout 3ms
Add one row while sorted, then recomputeabout 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.