Skip to content

Header filter row ​

A row of inputs under the headers, one per column. Type in a box and the filter applies; a column that is being filtered gets a colored box with a thick bottom border and a funnel button at its right end. The funnel clears only that column's filter and leaves the others; the × in the leftmost cell clears all filters. The row is not a new way of filtering. It is a screen for setFilterModel: a filter set from code shows in the boxes, and a filter typed in a box is what getFilterModel() returns.

Live demo — drawn by the real renderer

Turn it on ​

ts
const options: GridOptions<Row> = {
  columns: [
    { id: 'name', title: 'Name' },
    { id: 'salary', title: 'Salary', kind: 'number' },
  ],
  rows,
  rowKey: 'id',
  filterRow: true,
};
ValueMeaning
falseNo filter row (default)
trueAn input for every column that can be filtered
'auto'The row shows only if at least one column has a filter setting

A column with filterable: false or filter: false gets an empty cell. The row is as tall as headerHeight and stays pinned with the header when you scroll vertically. With the row on, the body is one line shorter, and aria-rowindex and aria-rowcount grow by one.

With the modular bundle, register the feature. The all-in-one bundle and the React, Vue and Angular wrappers already include it.

ts
import { createGrid } from 'maxgrid/core';
import { filter } from 'maxgrid/filter';

createGrid(el, { columns, rows, rowKey: 'id', filterRow: true, features: [filter] });

Passing filterRow or a column filter setting without the feature fails at creation with an invalid-option error that names the missing feature.

Choose the input per column ​

The input type follows the column kind. Use filter.type to change it.

kindInputCondition it makes
text, omitted, customText boxcontains by default; filter.operator for startsWith, endsWith, equals
numberNumber expression boxSee the table below
dateDate expression boxSee the table below; compares calendar days
booleanSelect (All, Yes, No)equals true or false
selectChecklist buttonin
ts
columns: [
  { id: 'name', filter: { operator: 'startsWith', placeholder: 'Starts with' } },
  {
    id: 'status',
    kind: 'select',
    filter: { options: [{ value: 'on', label: 'Enabled' }, { value: null }] },
  },
  { id: 'memo', filter: false }, // no box
];
filter settingMeaning
type'text', 'number', 'date', 'time', 'datetime', 'month', 'week', 'boolean' or 'set'
operatorOnly when the type is text. Default 'contains'
placeholderHint shown in the empty box
debounceMilliseconds to wait after typing. 0 to 150, default 120; anything else is invalid-option
optionsChoices for the checklist ({ value, label? }). Without it, the values come from the rows
Live demo — drawn by the real renderer

Numbers and dates take expressions ​

Number and date boxes take a short expression so one box can express every comparison. Spaces are ignored.

InputMeaning
5, =5Equal
!=5, <>5Not equal
>5 >=5 <5 <=5Greater, at least, less, at most
5..95 to 9, both ends included
5.., ..9At least 5, at most 9
-Only empty values

For dates, write the value as 2024-03-01. Dates compare as calendar days in the local time zone, so any time on that day counts as the day. An expression that cannot be read, or a date that does not exist (2024-02-30), is not applied; the box gets aria-invalid and a hint, and the filter that was already active stays.

Live demo — drawn by the real renderer
Live demo — drawn by the real renderer

Checklist ​

The cell of a kind: 'select' column is a button. Press it to open a checklist; each check applies one in condition right away, and unchecking everything removes it. A search box above the list narrows the values, and a list of more than 500 values shows the first 500. If the rows are not all loaded, as with server-side filtering, give the values with filter.options. An empty value is { value: null }.

The list closes when you press outside it, press Esc or scroll the grid. Closing with Esc returns focus to the button.

Live demo — drawn by the real renderer

Working with the filter model ​

  • Changing a box replaces only that column's conditions in the model. Conditions on other columns stay, even ones set from code.
  • Everything the row makes is AND. If the model was match: 'any', it becomes 'all' after a box changes.
  • When setFilterModel changes the model, the boxes follow. A box you are typing in is left alone if it still matches what the row last applied, and overwritten if code changed it.
  • A condition a box cannot show (for example gt on a text column) appears as Filter set. Typing in the box replaces it.
  • The × clear-all button sits in the row-number or checkbox cell if there is one, and otherwise at the right end of the first column's cell. It clears every condition, including ones set from code, and is disabled when nothing is filtered.
  • filterChanged fires once when a box changes, exactly as it does for setFilterModel.

When you also have a search box, set filter: false on the column the search box owns, and have the search box replace only its own column's condition instead of the whole model.

Live demo — drawn by the real renderer

The model is plain JSON, so you can save and restore it. Restoring fills the boxes too.

Live demo — drawn by the real renderer

Attach your own filter input ​

Give a column filterAdapter and your own input replaces the filter cell and the filter popup body for that column (1.3.6). It is a separate key from filter (the built-in input settings).

ts
{
  id: 'price',
  filterAdapter: () => {
    let input: HTMLInputElement;
    return {
      mount(el, { columnId, getModel, setModel }) {
        input = Object.assign(document.createElement('input'), { type: 'range', min: 0, max: 5000 });
        input.addEventListener('input', () =>
          setModel({ columnId, operator: 'gte', value: Number(input.value) }),
        );
        el.append(input);
      },
      destroy() {},
      focus: () => input.focus(),
    };
  },
}
  • The adapter writes one filter condition (FilterItem) of this column with setModel(item) and reads it with getModel(). It is the same filter model, so server mode and getViewState() stay serializable. Passing null clears the condition.
  • It is mounted inside the cell in the filter row and in the body of the filter popup. The popup applies live, so it has no apply button.
  • If mount or destroy throws, it is reported as callback-error and the cell stays empty. destroy() is called when the filter row or popup is redrawn or the grid is destroyed.
  • When the model changes from outside (clear all and so on) the adapter listens to filterChanged and updates itself.

Change the value the filter sees ​

By default the filter looks at the value getValue returns. To filter by something other than the visible text, or to filter object values, give the column the options below. Sorting, export and display keep using getValue.

OptionValueEffect
filterValue({ row, value, rowKey, columnId }) => valueThe value the filter test and the value list see; return a string, number, boolean, Date or null
valueKey(value) => stringA key for object values; the same key groups together and becomes one line in the value list
valueEquals(a, b) => booleanWhether two values are equal, used by the no-change check of updateRows and by change tracking (default deepEqual)
ts
{ id: 'hired', kind: 'date', filter: { type: 'set' },
  filterValue: ({ value }) => `${value.getMonth() + 1}`,         // a value list by month
{ id: 'owner', filter: { type: 'set' }, valueKey: (v) => `u${v.id}`,
  formatValue: (v) => v.label },                                   // object values grouped by id
  • For a column with filterValue, filter.type decides how it is filtered ('set' means text). Without it, date and time columns are filtered as text and other columns by their column kind.
  • If filterValue returns anything other than a string, number, boolean, Date or null, it is compared as text. The text of the value list is the value filterValue made.
  • With only valueKey, the value list text is the visible cell text (the formatValue result). The filter model holds the key text.
  • If a callback throws, or valueKey does not return a string, it is reported through the error event (callback-error) and the original value or the default key is used.
  • filterValue and valueKey are called once per row for each filter pass. Keep them cheap.

Choose how dates are typed ​

The date, time and datetime filter inputs use typing and a picker button together by default. Change that with the column's filter.dateInput.

ValueEffect
omitted or 'picker'Typing and a picker button (default)
'text'Typing only (no picker button)

It applies to the filter row and to the date conditions in the filter popup. Giving it to a column that is not a date kind is an invalid-option.

Korean input and keyboard ​

The boxes read the value from the input event, so Korean text filters while it is still being composed (ㅁ, 모, 목) after the debounce (120 ms by default, 150 ms at most). They do not wait for composition to end (Sorting and filtering).

Key or actionBehavior
EnterApplies the pending input now
EscClears that box and applies now
Enter or Esc while composingIgnored: those keys confirm or cancel the composition
Leaving the boxApplies the pending input
TabHeader, then the filter boxes in order, then the body

Keys typed in a filter box do not reach the grid's move and select keys. Each box has an aria-label (Filter {column}) and the row has role="row".

Filter on the server ​

With server paging (pagination.mode: 'server') the filter typed in the boxes goes to loadPage as query.filter. One request goes out when typing pauses, and the rows are replaced when the response arrives. Give the checklist its choices with filter.options.

Live demo — drawn by the real renderer

Other settings ​

Live demo — drawn by the real renderer
  • Messages (filterMessages) default to Korean or English by locale, and you can override some of them.
  • Colors use the existing tokens such as --mxg-bg-header, --mxg-border, --mxg-accent and --mxg-control-*. Light, dark and the three densities need no extra setup.
  • With 24 or more columns the body draws only the visible columns, but the filter row builds every cell once, so the box you are typing in survives horizontal scrolling.
  • Moving or resizing columns moves the row with them, and rebuilding it keeps the focus and cursor position.

Limits ​

  • The row height is fixed to headerHeight.
  • Number boxes take expressions only (>=100, 10..20). Date and time boxes get a calendar or clock button (from 1.2.0) and still accept expressions.
  • A text box has one operator per column. For a choice of operators, build your own screen and call setFilterModel.
  • The popup style, opened with a funnel button in each header, is in Column filter popup and sort marks.