Skip to content

Filter presets (named filter sets) ​

Since 1.6.0

filterPresets and filterPopupActions were added in 1.6.0.

Keep the filters you use often, such as "Overdue this month" or "My team's requests", under a name and bring them back in one step. A preset stores the filter model (getFilterModel()) and, if you want, the sort (getSortModel()). Nothing changes unless you turn it on (default false).

Try it in the gallery example Save and reuse filters.

Turn it on ​

ts
createGrid(el, {
  columns,
  rows,
  rowKey: 'id',
  filterMenu: true,
  filterPresets: true,
});

With filterMenu (the header funnel popup) a Presets area appears at the bottom of the popup. The API works without filterMenu too.

OptionDefaultDescription
storageKeynoneSaves the list to localStorage under maxgrid:filter-presets:<storageKey>. Falls back to memory when storage is blocked
items[]The initial list. Stored values win over it
max20Maximum number of presets (1 to 200)
allowDeletetrueWith false the popup delete button and deleteFilterPreset are blocked
includeSortfalseWhether saving includes the sort by default

filterPresets: true equals {}. A wrong option shape throws invalid-option when the grid is created.

Use it in the popup ​

Everything is in the Presets area at the bottom of the popup.

  • Click a name, or press Enter or Space on it, to apply that filter and close the popup. The preset that equals the current filter is marked "Applied".
  • The first row, Clear filter, removes every filter.
  • Type a name in the name box and press Enter (or the Save button) to save the current filter. Saving under an existing name replaces that preset. Tick Include sort to store the sort as well.
  • For the preset you picked, Rename (F2) and Delete (Delete, with one confirmation) are available.
  • Arrow keys, Home and End move through the list. Screen readers announce the listbox and the result messages (saved, deleted).

Use it from code ​

ts
const saved = api.saveFilterPreset('Overdue this month', { includeSort: true });
api.applyFilterPreset(saved.id); // a name works too: api.applyFilterPreset('Overdue this month')
api.renameFilterPreset(saved.id, 'Overdue');
api.deleteFilterPreset('Overdue');

const list = api.getFilterPresets(); // a copy
api.setFilterPresets(list); // replace the whole list
APIWhat it does
getFilterPresets()Returns the list (a copy)
setFilterPresets(list)Replaces the list. Checks shape, names and count
saveFilterPreset(name, { includeSort? })Saves the current filter (and sort). The same name replaces that preset
applyFilterPreset(idOrName, { source? })Applies it. Returns false when beforeFilterPresetApply vetoes it
renameFilterPreset(idOrName, name)Renames it
deleteFilterPreset(idOrName)Deletes it

A name is 1 to 40 characters after trimming. A bad name, an unknown preset, going over max, or calling while the option is off throws invalid-option and changes nothing. Applying goes through setFilterModel and setSortModel, so beforeFilter and filterChanged fire as usual.

Events and hook ​

ts
createGrid(el, {
  // …
  filterPresets: { storageKey: 'orders' },
  hooks: {
    beforeFilterPresetApply: ({ preset, source }) => {
      if (preset.name === 'Private') return false; // cancel the apply
    },
  },
});
api.on('filterPresetsChanged', ({ presets }) => save(presets)); // to store on a server
api.on('filterPresetApplied', ({ preset }) => console.log(preset.name));

source is 'user' when the popup applies it and 'api' when your code calls it. If the hook throws, the apply goes ahead and an error event is emitted.

Where presets are stored ​

  • With storageKey they live in the browser localStorage and survive a reload (visible to the same site in the same browser only).
  • To keep them per user on a server, leave storageKey out, pass the first list as items and send filterPresetsChanged to your server.
  • If storage is blocked or the stored value is broken, the grid quietly keeps them in memory.

A preset is { id, name, model, sort?, createdAt }. model has the same shape getFilterModel() returns.

Add your own buttons to the popup ​

filterPopupActions adds buttons at the bottom of the filter popup (next to the presets area). It does not depend on presets.

ts
createGrid(el, {
  // …
  filterMenu: true,
  filterPopupActions: [
    {
      id: 'only-mine',
      label: { ko: '내 것만', en: 'Only mine' },
      run: (api) =>
        api.setFilterModel({
          match: 'all',
          items: [{ columnId: 'owner', operator: 'equals', value: me }],
        }),
    },
  ],
});

label is a string or { ko, en }. A click calls run(api) and closes the popup. If run throws, an error event is emitted and the popup stays open. Ids must be unique.

Accessibility and look ​

The list is a role="listbox", the button row a role="toolbar", and result messages are read through aria-live. The same structure works in the dark theme, right-to-left writing and narrow screens (bottom sheet, 44px rows). Texts come in Korean, English, Japanese and Simplified Chinese, and you can change them with the filter.menuPreset* keys of a language pack.