Skip to main content
Login

Sign in to access your account

Filter - National Design System

Filter narrows a list to the items that match a search term and the options the user picks.

Overview

A filter is a set of elements that share one data-filter-target: the id of the container that holds the items. Each element is a surface of the filter: a search box, a nds-filter Dropmenu of option groups, a row of applied filters, a count. The surfaces need no common parent, so a Toolbar usually holds them above the items. Each item carries data-filter marks with its values, and the menu’s options match against them.

Pick another component when:

  • the user moves between sections, not values in one list: Tabs or Side Menu
  • the field suggests matches as the user types: Autocomplete
  • the user picks values for a form, not for a list: Multiselect

Markup

Options
Group options
Sector type
Menu
More
Preview
  • Commercial registration Updated
    200
    Business
  • Building permit Updated
    1500
    Housing
  • Vehicle registration renewal Updated
    100
    Transport
  • Driver's license renewal Updated
    400
    Transport
  • Municipal license Updated
    800
    Business
  • Housing support request Updated
    Free
    Housing
  • Trade name reservation Updated
    200
    Business
  • Truck operating card Updated
    2500
    Transport
<div class="nds-toolbar"> <div class="nds-form-container nds-search-box" data-filter-target="flt-items"> <div class="nds-search-content"> <div class="nds-form-control"> <i class="nds-icon nds-hgi-search-01" aria-hidden="true"></i> <input type="text" id="flt-search-input" class="nds-search-input" placeholder="Search services..." aria-label="Search services"> <div class="nds-form-action"> <button class="nds-btn nds-subtle nds-clear nds-icon-only" type="button" hidden aria-label="Clear search" data-i18n-aria-label="form.clear_search"> <i class="nds-icon nds-hgi-cancel-01" aria-hidden="true"></i> </button> </div> </div> <button class="nds-btn nds-primary nds-search-btn" type="button"> <i class="nds-icon nds-hgi-search-01" aria-hidden="true"></i> <span class="nds-label" data-hidden="sm sr" data-i18n="filter.search">Search</span> </button> </div> </div> <div class="nds-dropmenu nds-filter" data-filter-target="flt-items"> <button class="nds-btn nds-neutral nds-menu-btn nds-filter-btn nds-dropmenu-trigger" type="button"> <i class="nds-icon nds-hgi-filter"></i> <span class="nds-label" data-hidden="sm sr" data-i18n="filter.filter">Filter</span> </button> <div class="nds-dropmenu-menu" hidden> <div class="nds-dropmenu-scroll"> <div id="flt-sector" data-filter="sector" data-filter-type="checkbox" data-filter-legend="Sector"></div> <div data-filter="fee" data-filter-type="slider" data-filter-legend="Fee" data-filter-min="0" data-filter-max="3000" data-filter-step="100" data-filter-currency="SAR"></div> <fieldset class="nds-form-group nds-dropmenu-group" data-filter="updated"> <legend class="nds-label">Updated</legend> <div class="nds-form-container nds-date-picker nds-date-range"> <div class="nds-form-control"> <div class="nds-form-action"> <button type="button" class="nds-btn nds-subtle nds-md nds-date-picker-toggle nds-icon-only" aria-label="Open calendar" data-i18n-aria-label="date-picker.open_calendar"> <i class="nds-icon nds-hgi-calendar-03" aria-hidden="true"></i> </button> </div> <input type="text" id="flt-updated" class="nds-input nds-date-input" placeholder="DD/MM/YYYY - DD/MM/YYYY" aria-label="Updated"> </div> <input type="hidden" class="nds-date-value" data-date-format="YYYY-MM-DD" data-calendar="gregory"> <input type="hidden" class="nds-date-value" data-date-format="YYYY-MM-DD" data-calendar="gregory"> </div> </fieldset> </div> <div class="nds-dropmenu-footer"> <hr class="nds-divider"> <div class="nds-dropmenu-action"> <button class="nds-btn nds-secondary nds-dropmenu-item" type="button" data-filter-action="clear" data-no-auto-close> <span class="nds-label" data-i18n="filter.reset">Reset</span> </button> <button class="nds-btn nds-primary nds-dropmenu-item" type="button" data-filter-action="apply"> <span class="nds-label" data-i18n="filter.apply">Apply</span> </button> </div> </div> </div> </div> <div class="nds-filter-applied" data-filter-target="flt-items" hidden> <span class="nds-label" data-i18n="filter.applied_filters">Applied Filters:</span> <div class="nds-chips"></div> </div> </div> <ul id="flt-items" class="nds-list nds-grid nds-paged-content nds-stroke" data-filter-items="nds-card" style="--per-page: 6; --max-col: 3; --mid-col: 2; --min-col: 1;"> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Commercial registration</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-02" data-filter="updated" data-filter-value="2026-10-02">2 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="200">200</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Business</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Building permit</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-06" data-filter="updated" data-filter-value="2026-10-06">6 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="1500">1500</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Housing</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Vehicle registration renewal</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-09" data-filter="updated" data-filter-value="2026-10-09">9 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="100">100</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Transport</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Driver's license renewal</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-13" data-filter="updated" data-filter-value="2026-10-13">13 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="400">400</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Transport</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Municipal license</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-15" data-filter="updated" data-filter-value="2026-10-15">15 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="800">800</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Business</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Housing support request</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-18" data-filter="updated" data-filter-value="2026-10-18">18 Oct 2026</time></span> </div> <div class="nds-card-value"> <span data-filter="fee" data-filter-value="0">Free</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Housing</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Trade name reservation</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-21" data-filter="updated" data-filter-value="2026-10-21">21 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="200">200</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Business</span></span> </div> </div> </li> <li class="nds-card nds-page-item"> <div class="nds-card-content"> <div class="nds-card-text"> <span class="nds-card-title">Truck operating card</span> <span class="nds-card-subtitle">Updated <time datetime="2026-10-27" data-filter="updated" data-filter-value="2026-10-27">27 Oct 2026</time></span> </div> <div class="nds-card-value"> <span class="nds-number-format" data-currency="SAR" data-filter="fee" data-filter-value="2500">2500</span> </div> <div class="nds-card-tags"> <span class="nds-tag nds-blue"><span class="nds-label" data-filter="sector">Transport</span></span> </div> </div> </li> </ul> <nav class="nds-pagination" data-auto-pagination="flt-items" aria-label="Services pagination"></nav>

Behavior

Option Groups

An element with data-filter in the menu is a group. Its options come from one of four places: the marks on the items (data-filter-type), a list on the group (data-filter-values), inputs you write, or your script (renderFilter()). From the marks, the script makes one option per value it finds, sorted, in a <fieldset> that replaces the element.

The user picks values in the menu, and Apply applies them all at once. Closing the menu without Apply puts back the values that were applied, so the search box or a chip never applies a value the user did not apply. In a surface with no Apply button, a pick applies at once, and closing the menu keeps it. A checkbox or switch group matches an item that has any picked value. An item must match every group that has a value.

Values and Labels

A mark’s text is its value. data-filter-value on the mark sets a value apart from the text: the URL and the match use the value, and the option and the chip show the text. data-filter-values on a group lists its options: an array of values, or an object of value-label pairs. The script then reads no items for that group.

A filter can also drive a view that holds no items, such as a Calendar or a map. Point data-filter-target at the view, give each group data-filter-values, and update the view from criteria.filters in nds:filter:change. The view has no .nds-card (or nothing that matches its data-filter-items), so the filter hides nothing in it and shows no alert.

Range Slider

data-filter-type="slider" builds a Slider over the number in each item’s data-filter-value. With data-filter-min and data-filter-max it has two thumbs. With data-filter-max alone it has one thumb, “up to”, from 0. The applied range shows as one chip, and removing it puts both thumbs back at the ends. In the URL and the request, a range is two keys: fee-min=200&fee-max=1500. An “up to” slider sends fee-max only. For other keys, write the slider yourself and name its thumbs (see Manual Options). The chip groups thousands only when the slider’s output does: with data-filter-currency or data-filter-unit, or when your own output has .nds-number-format.

Date Range

A group that holds a Date Picker filters by date. In range mode (nds-date-range) the user picks a first and a last day. A single picker picks one day, or a whole month or year when its format has no day (MM/YYYY, YYYY), Hijri months and years too. Give the picker two .nds-date-value inputs (one for a single day) with data-date-format="YYYY-MM-DD" and data-calendar="gregory": the script reads the days there, so the field may show Hijri. Each item’s mark carries its day in data-filter-value as a Gregorian YYYY-MM-DD, or as a date and time; any other format never matches, and the console says so. The applied range shows as one chip in the field’s format, and removing it clears the field. A range with one end, from a link or setFilterValues(), shows ≥ or ≤ before its day, as the slider’s “up to” does. In the URL and the request it is two keys, updated-min=2026-10-06&updated-max=2026-10-18, and an open end is left out. A single picker sends the first and the last day of its pick. A name on a .nds-date-value sets its key, such as from and to.

The date group can also sit outside the menu, in the toolbar beside the search box: give its <fieldset> the filter’s data-filter-target, and leave out nds-dropmenu-group. There no Apply button reaches it, so a date applies as soon as the user saves it in the calendar or types it, as a search applies on Enter. In a filter form (server mode), or in a panel with its own Apply button, it waits for the submit or the Apply like the other groups, and the request carries its two keys.

Manual Options

Leave out data-filter-type and write the inputs in the group yourself, as a Checkbox or Radio group. The script reads every checkbox, radio and .nds-switch-input in it, and the chip shows the option’s .nds-label. Each value matches a mark’s value, in any letter case. Inputs added later join the group by themselves. For Option search, add data-search-item to each .nds-form-container.

A group that holds a range Slider (.nds-slider-container) is a range filter on your slider: its min and max are the full range. Put data-filter-currency or data-filter-unit on the group for the chip. A name on a thumb sets its key in the URL and the request.

Options from a Script

renderFilter(name, values, type) builds a group’s options from values your script fetched, and a second call replaces them. Use it for cascading groups: call it again when the parent group changes. Leave data-filter-type off that group, as below. refresh() rebuilds every group that has it from the items, and would replace your values.

// In the menu: <div data-filter="entity" data-filter-legend="Entity"></div> NDS.Filter.whenReady('.nds-filter[data-filter-target="services-results"]', function (filter) { NDS.request('/api/entities', { json: true }).then(function (res) { filter.renderFilter('entity', res.data.map(function (entity) { return entity.name; }), 'checkbox'); }); });

Collapsible Groups

data-filter-accordion turns one group into an Accordion item, closed at load, with data-filter-legend as its header. A tag on the header counts the picked values and hides at zero. Each such group is its own accordion. Wrap several in one <div class="nds-accordion"> to make them one. With Option search on the menu, a search term opens every group. Clearing it, or closing the menu, closes the groups it opened.

Applied Chips

A nds-filter-applied row with a nds-chips element inside shows one chip per applied value, and one for the search term. Removing a chip removes its value and applies the rest at once. data-chip-class on the row sets the chips’ classes. With a [data-filter-query] element on the filter, the search term shows there, in quotes, and gets no chip.

Suggestions

A nds-auto-fill row holds nds-item chips. A click writes the chip’s text into the field named by data-target, and data-autofill-apply also runs the search. Give the row data-filter-target too. When the filter also has an applied-chips row, it hides the suggestions while a value or a search term is applied. For suggestions that come from a server as the user types, add Autocomplete to the search box.

Form Submission

For results from a server, add a <form> with the same data-filter-target and data-filter-submit. Apply, the search box, the menu’s Reset and every chip removal then submit the form, and the server returns the filtered page. The script writes the form’s id into the form attribute of each control in the surfaces, so a surface outside the form still submits. Give the form an id. The request and the URL are one query, under the names you write: a group sends one key per value (sector=business&sector=housing), and a range one key per end. The script puts a range end with no name, and a search field with no name, in hidden inputs.

<form id="services-form" data-filter-target="services-results" data-filter-submit method="get" action="/services"> <div class="nds-toolbar"> <div class="nds-form-container nds-search-box" data-filter-target="services-results"> <div class="nds-search-content"> <div class="nds-form-control"> <i class="nds-icon nds-hgi-search-01" aria-hidden="true"></i> <input type="text" name="search" class="nds-search-input" placeholder="Search services..." aria-label="Search services"> </div> <button class="nds-btn nds-primary nds-search-btn" type="button"> <i class="nds-icon nds-hgi-search-01" aria-hidden="true"></i> <span class="nds-label" data-hidden="sm sr" data-i18n="filter.search">Search</span> </button> </div> </div> <div class="nds-dropmenu nds-filter" data-filter-target="services-results"> <button class="nds-btn nds-neutral nds-menu-btn nds-filter-btn nds-dropmenu-trigger" type="button"> <i class="nds-icon nds-hgi-filter"></i> <span class="nds-label" data-hidden="sm sr" data-i18n="filter.filter">Filter</span> </button> <div class="nds-dropmenu-menu" hidden> <div class="nds-dropmenu-scroll"> <div data-filter="sector" data-filter-type="checkbox" data-filter-legend="Sector" data-filter-values='{"business":"Business","housing":"Housing","transport":"Transport"}'></div> </div> <div class="nds-dropmenu-footer"> <hr class="nds-divider"> <div class="nds-dropmenu-action"> <button class="nds-btn nds-secondary nds-dropmenu-item" type="button" data-filter-action="clear" data-no-auto-close> <span class="nds-label" data-i18n="filter.reset">Reset</span> </button> <button class="nds-btn nds-primary nds-dropmenu-item" type="button" data-filter-action="apply"> <span class="nds-label" data-i18n="filter.apply">Apply</span> </button> </div> </div> </div> </div> <div class="nds-filter-applied" data-filter-target="services-results" hidden> <span class="nds-label" data-i18n="filter.applied_filters">Applied Filters:</span> <div class="nds-chips"></div> </div> </div> </form> <div id="services-results" class="nds-empty"> <!-- The server writes the matching services here --> </div>

A group on a server page lists its options with data-filter-values: the page holds only one page of results, and options read from it would miss the others. Generated options submit under the group’s name, one key per value, as in the URL. The page the form loads reads them back, so the options stay picked and the chips show.

AJAX Submission

data-ajax on the form sends the request without a page load. For an HTML response, the script swaps the item container for the element with the same id in the response. It stops the components in the old container and starts the ones in the new container before nds:filter:success fires, so the page calls nothing for them. A response without that element counts as a failure. For a response with a JSON Content-Type, the script changes no items: render them in nds:filter:success. While a request runs, the menu takes no clicks and the button that sent it shows a spinner. A newer request cancels the one in flight.

var filter = document.querySelector('.nds-filter[data-filter-target="services-results"]'); filter.addEventListener('nds:filter:success', function (e) { if (!e.detail.isJson) return; var list = document.getElementById('services-results'); list.replaceChildren(); e.detail.data.records.forEach(function (record) { var card = document.createElement('div'); card.className = 'nds-card nds-stroke'; var title = document.createElement('span'); title.className = 'nds-card-title'; title.textContent = record.title; card.appendChild(title); list.appendChild(card); }); list.setAttribute('data-total-count', e.detail.data.total); });

On a failure the items stay as they were, and so do the chips, the badge, the options and the URL: the script puts them back to match the items. An unapplied pick in the open menu is lost. The script shows an error toast, unless a listener calls preventDefault() on nds:filter:error. The no-results alert never shows in form mode: call showNoResultsAlert() from your response handler.

Your Own Request

Call preventDefault() on nds:filter:request to send the request yourself, such as a POST with a JSON body. The event fires for Apply, a chip removal, the menu’s Reset, reset() and the search box. The chips, the badge and the URL already show the new filters when it fires: call detail.rollback() if your request fails.

The event fires on the filter and bubbles, so a form that does not hold the filter never hears it. Listen on document and check detail.form. In detail.criteria, each group in filters is an array of values, even with one value picked. A range is one min-max string in it. The search term is the search string.

var form = document.getElementById('services-form'); document.addEventListener('nds:filter:request', function (e) { if (e.detail.form !== form) return; e.preventDefault(); NDS.request('/api/services', { method: 'POST', body: new FormData(form), json: true }) .then(function (res) { renderServices(res.data.records); }) .catch(function () { e.detail.rollback(); }); });

The filter reads the address at load and shows its filters in the search box, the chips and the menu, but it sends no request. When your script loads the first items from your own API, send that first request with the same filters: NDS.Filter.whenReady() gives you the filter, and getCriteria() its filters. Turn on the Pagination URL sync (data-page-param) so the page stays in the address too, and send the first request for that page: a shared link then opens the same page.

// First load: the filters and the page that the address already holds. NDS.Filter.whenReady(form, function (filter) { var page = Number(new URLSearchParams(location.search).get('page')) || 1; loadServices(filter.getCriteria(), page); });

Sort

A filter also drives the Sort triggers that carry its data-filter-target. Copy the Sort menu from its page, and write data-filter-target on each trigger where Sort has data-sort-target. Put the menu beside the filter. Each item carries the value it sorts by in data-sort-<key>, such as data-sort-title="Commercial registration".

The sort stays in the URL as sort, with order=desc for a descending order. Ascending writes no order. A sort in the URL wins over a sorted-asc or sorted-desc state written on a trigger, so a shared link opens in its own order. On a page with sort buttons, do not use sort or order for anything else, not even as a group name: a descending sort writes order=desc over it.

Sort is not a filter value. Decide by what the server returns. All matching items, paged in the browser: add data-sort triggers, and the browser sorts. One page of items: the server sorts, so add no data-sort. Put the Dropmenu picker in the form instead, with data-select-name="sort" and the filter’s data-filter-target, and give each item the value your server reads, such as data-value="title-asc". A pick sends the form. The request and the URL carry its value, and a reload picks it again.

Built-in Features

  • Auto-initialization

    The script starts one filter for each data-filter-target value and joins every element that carries it. A search box alone is a working filter.

  • Shareable URL State

    The search term and the applied values stay in the URL query, so a reload or a shared link opens the same list. The search term's key is the search field's name, or search when it has none. A group's key is its data-filter name, once per value, and a range has a key for each end. Links that joined the values with commas still open, so a checkbox or switch value must not contain a comma. The sort is sort and order.

  • No Results Alert

    When no item matches, a warning alert with a Clear filters button shows in the item container. It closes when items match again. data-filter-no-results on the container sets its text. A container with no items at all shows no alert: give it Empty for that message.

  • Filter Count Badge

    When a filter changes the count, a screen reader hears the count line, in your words. The nds-filter-btn trigger shows a badge with the number of applied values. The Apply button adds the number of picked values to its label.

  • Any Item Type

    Cards by default. data-filter-items sets the items: a class, a tag such as tr, or any selector. On a table, put it and the container's id on the <tbody>: it takes only the body's own rows.

  • Pagination Support

    In a Pagination container, the pages hold only the matching items, and a new filter goes back to page 1.

  • No Flash on Load

    A container with data-filter-items stays hidden until its filter has applied the values in the URL. A shared link never shows the full list first.

  • Deferred Option Build

    Options for a group in the closed menu are built on its first open, not at page load. A group with a value in the URL is built at load.

  • Keyboard

    Enter in the search box runs the search. Enter in the open menu runs Apply. Every option is a real input in a <fieldset> with its legend. Slider thumbs have labels and move with the arrow keys.

  • Programmatic Control

    Set values and the search term, read the criteria and the matching items, or reset the filter from a script, through NDS.Filter.

Best Practices

  • Filter in the browser when every item is on the page and the list is short, up to a few hundred items. For more, use form submission.
  • Pick the group type by the question. Checkbox: any of several values. Radio: exactly one, with All to undo it. Switch: on/off features. Slider: a number range.
  • Give a yes-or-no field a Radio group, so All undoes the pick. Give a number field a Slider.
  • Keep a Reset button (data-filter-action="clear") next to Apply in the menu footer.
  • Keep hidden on the applied-chips row. The script shows it once a value is applied.
  • Keep legends to one or two words. data-filter-legend is the group’s heading in the menu.
  • Make a group with many options collapsible, and keep a group of 3 or 4 options open.
  • Give each mark a value with data-filter-value when its text is translated or formatted, such as a price that reads “SAR 250”.
  • Put data-filter-items only on a container that has a filter. The container stays hidden until a filter starts on it.
  • On a paged list, show the count with the Pagination records counter in place of data-filter-count: it counts the matching items and adds the range shown.
  • Give each filter on a page its own group names: the names are the URL keys, and two filters with one name share it.
  • To keep a URL key that links already use, write it as the group name, or as the search field’s name for the search term.
  • Add data-filter-ignore to a text field inside a surface that is not the filter’s search, so the script does not take it as one.

API

Other Classes

Class Element Effect
nds-filter the filter’s .nds-dropmenu Marks the menu of option groups. The filter’s events fire on it
nds-filter-btn the menu’s trigger button Shows the count badge, and the spinner while a form submits. data-filter-btn does the same
nds-filter-applied a surface with a .nds-chips inside The row of applied chips
nds-auto-fill a surface with .nds-item chips The row of suggestions. Hidden while a filter is applied, when the filter has an applied-chips row
nds-filter-menu the filter’s .nds-dropmenu-menu The script adds it. Style the menu by this class: it can move to <body>
nds-filter-range the <fieldset> of a slider group The script builds it
nds-filter-hidden-inputs a <div> in the submission form The script builds it and writes the hidden inputs into it on each submit

Data Attributes

Attribute Element Effect
data-filter-target every surface, and the submission <form> The id of the item container. Every element with the same value is part of one filter
data-search .nds-filter A search box at the top of the menu narrows the options. A number shows it only from that many options. See Dropmenu
data-filter an element in a surface A group. The value is the group’s name and its URL key
data-filter="search" a text field in a surface, or its wrapper The search field. In the menu, Apply runs it. A .nds-search-input outside the menu needs no attribute
name the search field The search term’s URL key. With no name, the key is search. name="q" keeps a q key that links already use
data-filter-type a group checkbox, radio, switch or slider: the script builds the options. Without it, the script uses the inputs you write in the group, or the options of renderFilter()
data-filter-legend a group The group’s heading
data-filter-values a group with checkbox, radio or switch The options as JSON: an array of values, or an object of value-label pairs. The script reads no items for this group
data-filter-variant a group A class the script adds to each input (on a switch, to its .nds-switch-toggle), such as nds-primary
data-filter-all-label a radio group The label of the All option. The default is All, or الكل on an Arabic page
data-filter-no-all a radio group No All option
data-filter-accordion a group Makes it a collapsible Accordion item
data-filter-min, data-filter-max a slider group The ends of the range. With data-filter-max alone, the slider has one thumb from 0. data-filter-max is required and must be above the minimum
data-filter-step a slider group The step of a thumb. The default is 1
data-filter-currency a slider group A currency code, such as SAR, on the slider values and the chip
data-filter-unit a slider group A unit after the slider values and the chip, such as km. For a value that is not money
data-filter-action a button in a surface apply applies the picked values and closes the menu. clear clears the menu’s values and applies the result, with the menu open. reset clears every value and the search term
data-filter-count an element in a surface The script writes the number of matching items into it
data-filter-query an element in a surface The script writes the search term into it, in quotes. The search term then gets no chip
data-chip-class .nds-filter-applied The classes of each chip. The default is nds-primary
data-target .nds-auto-fill The id or name of the field a chip fills
data-autofill-apply .nds-auto-fill A chip click also runs the search
data-filter-ignore a text field, or an element around it The script does not use the field as the search field
data-filter-items the item container The items: a class name without the dot, a tag, or a selector. The default is .nds-card. With it, the container stays hidden until the filter starts
data-filter-no-results the item container The no-results alert’s text, in place of “No item matches the current filters.” Say what the user can change, such as “No requests match. Try another status”
data-total-count the item container A count from the server. [data-filter-count] shows it in place of the matching items
data-filter an item, or an element inside one A mark: the item’s value for the group with that name. Its text is the value
data-filter-value a mark The value in place of the text. A slider group reads it as a number
data-filtered an item The script sets it on an item that does not match, and removes it when the item matches again. CSS hides the item. Do not write it
data-filter-submit a <form> with data-filter-target The filter submits this form in place of filtering in the browser
data-ajax the submission <form> Sends it without a page load
data-state="submitting" .nds-filter The script sets it when the form submits, and removes it when the response arrives or fails. While it is set, the menu takes no clicks
data-state="loading" .nds-filter-btn, or the search button The script sets it on the button that submitted the form, and removes it when the response arrives or fails

CSS Custom Properties

Property Default Controls
--dropmenu-min-width 250px The menu’s minimum width. Set it on .nds-filter: the menu keeps it when it moves to <body>

Tokens

It reads these shared tokens. A change to one also changes other components: see Tokens.

Source: the var() reads in _sass/components/_filter.scss.

TokenPreviewValue
--text-display
Read by color

var(--colors-neutral-800)
Dark mode var(--colors-neutral-100)

JavaScript

NDS.Filter loads after the page shows. Until then each call returns a Promise, so a sync read such as getInstance() returns no instance. Use whenReady() from your own scripts.

Method Effect
NDS.Filter.init() Starts a filter for each data-filter-target value that has none
NDS.Filter.create(element) Starts the filter of one surface and returns it. On a started filter, it returns that one
NDS.Filter.destroy(element) The same as destroy(). Any element of the filter’s surfaces works
NDS.Filter.getInstance(element) The filter of any surface, by element or selector
NDS.Filter.getByTarget(id) The filter of an item container id
NDS.Filter.whenReady(element, callback) Runs callback with the filter, now or once it starts
NDS.Filter.refresh(container) Runs refresh() on each filter whose item container is container, is inside it, or holds it. Starts the filters of new surfaces in it first. Skips form-mode filters. NDS.init.refresh(container) calls it for you
setFilterValues(name, values) Picks these values in the group, and applies them. An empty array clears the group. On a slider group, pass one lo-hi string, for example ['200-1500']. On a date group, pass one from..to string of YYYY-MM-DD days, either end left out for an open range: ['2026-10-01..2026-10-15'], ['..2026-10-15']
setSearchValue(text) Sets the search term, and applies it
removeFilterValue(name, value) Removes one value, and applies the rest
removeSearchFilter() Clears the search term, and applies
resetRangeFilter(name) Puts a slider group back to its full range, and applies
renderFilter(name, values, type) Builds the group’s options from values. type is checkbox by default
getCriteria() A copy of the criteria: { search, filters: { name: [values] } }
getVisibleItems(), getHiddenItems() The matching items, and the others
syncFilters() Applies the picked values. In form mode it updates the chips, the badge and the URL, and does not submit
submitForm() Submits the form in form mode
clear() Clears every value, the search term and the sort, and applies nothing
reset() Clears everything and shows every item. In form mode it submits the form again
refresh() Reads the items again and rebuilds the groups that have data-filter-type and no data-filter-values, keeping the current page. New items join the active sort
reapplyUrlParamsForFilter(name) Picks the URL’s values in a group whose inputs you added after load
showNoResultsAlert(), dismissNoResultsAlert() Shows or closes the no-results alert in the item container. Call them from your response handler in form mode. Without an item container they do nothing
clearDropmenuFilters() Empties every dropmenu group
syncUrlParams() Writes the criteria to the URL
queryAll(selector) Returns the matches inside the filter’s own surfaces only
targetId, items, criteria, filterInputs, sort, isFormMode, isAjaxMode Properties. Read-only
destroy() Removes the listeners and shows every item

In form mode, each setter submits the form. Setters in one script run share one submit, and a submitForm() in that run replaces it.

Event Fired on Detail
nds:filter:ready .nds-filter, or the first surface { instance }: the filter’s instance
nds:filter:change the same { filter, criteria, totalItems, visibleItems, hiddenItems }. filter is the element the event fires on. It fires after each apply, also when nothing is applied, and after reset(), once the URL, the chips and the page have updated. The last three are numbers, null in form mode. The values are in criteria.filters, not in criteria
nds:filter:reset the same { filter, totalItems }
nds:filter:clear the same { filter }, on clear(), reset() and the menu’s Reset
nds:filter:submit the same { criteria, form }, before a form submits with a page load, after its fields pass. preventDefault() stops it
nds:filter:request the same { criteria, form, hiddenInputsContainer, rollback }, before an AJAX request. preventDefault() stops the request. Add your own fields to hiddenInputsContainer here
nds:filter:success the same { success, isJson, data, html, fullHtml, form }, after an AJAX response. data is the JSON, html the new container’s HTML, fullHtml the whole response, to update parts outside the container, form the element the event fires on
nds:filter:error the same { error, form }, after a network error, an error status, a timeout, or a response without the item container. preventDefault() stops the error toast
nds:form:valid, nds:form:invalid the same As in Forms, for a submission form without data-ajax
var menu = document.querySelector('.nds-filter[data-filter-target="flt-items"]'); menu.addEventListener('nds:filter:change', function (e) { console.log(e.detail.criteria.filters.sector, e.detail.visibleItems); }); NDS.Filter.whenReady(menu, function (filter) { filter.setFilterValues('sector', ['Business']); });

The full API is in the banner of _js/nds-filter.js.

Last Modified Date: 16/11/2026 - 09:13 PM
Was this page useful?
60% of users said Yes from 2843 Feedbacks