widgets numericMenu

Edit this page

Description

The numeric menu is a widget that displays a list of numeric filters in a list. Those numeric filters are pre-configured with creating the widget.

Requirements

The attribute passed to attribute must be declared as an attribute for faceting in your Algolia settings.

The values inside this attribute must be JavaScript numbers and not strings.

Live example

You can find an example at the end of the page or a live example in our widget showcase.

Usage

Usage
const search = instantsearch( /* parameters */ );

const widget = instantsearch.widgets.numericMenu({ container: string|HTMLElement, attribute: string, items: Array<NumericMenuOption>, templates: [NumericMenuTemplates], cssClasses: [NumericMenuCSSClasses], transformItems: [(Array<object>) => Array<object>], }: NumericMenuWidgetOptions);
search.addWidget(widget);

Options

NumericMenuWidgetOptions

  • containerstring|HTMLElement

    CSS Selector or HTMLElement to insert the widget.

  • attributestring

    Name of the attribute for filtering.

  • itemsArray<NumericMenuOption>

    List of all the items.

  • templates[NumericMenuTemplates]

    Templates to use for the widget.

  • cssClasses[NumericMenuCSSClasses]

    CSS classes to add to the wrapping elements.

  • transformItems[(Array<object>) => Array<object>]

    Function to transform the items passed to the templates.

NumericMenuOption

  • namestring

    Name of the option.

  • startnumber

    Lower bound of the option (>=).

  • endnumber

    Higher bound of the option (<=).

NumericMenuTemplates

  • item[string|function]

    Item template, provided with label (the name in the configuration), isRefined, url, value (the setting for the filter) data properties.

NumericMenuCSSClasses

  • root[string|Array<string>]

    CSS class to add to the root element.

  • noRefinementRoot[string|Array<string>]

    CSS class to add to the root element when no refinements.

  • list[string|Array<string>]

    CSS class to add to the list element.

  • item[string|Array<string>]

    CSS class to add to each item element.

  • selectedItem[string|Array<string>]

    CSS class to add to each selected item element.

  • label[string|Array<string>]

    CSS class to add to each label element.

  • labelText[string|Array<string>]

    CSS class to add to each label text element.

  • radio[string|Array<string>]

    CSS class to add to each radio element (when using the default template).

Widget

  • render[function]

    Called after each search response has been received

  • getConfiguration[function]

    Let the widget update the configuration of the search with new parameters

  • init[function]

    Called once before the first search

Example

search.addWidget(
  instantsearch.widgets.numericMenu({
    container: '#popularity',
    attribute: 'popularity',
    items: [
      { label: 'All' },
      { end: 500, label: 'less than 500' },
      { start: 500, end: 2000, label: 'between 500 and 2000' },
      { start: 2000, label: 'more than 2000' }
    ]
  })
);

Can't find what you are looking for? Open an issue, we'll get back to you.