widgets rangeSlider

Edit this page

Description

The range slider is a widget which provides a user-friendly way to filter the results based on a single numeric range.

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 (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.rangeSlider({ container: string|HTMLElement, attribute: string, tooltips: [boolean|RangeSliderTooltipOptions], cssClasses: [RangeSliderCssClasses], pips: [boolean], precision: [number], step: [number], min: [number], max: [number], }: RangeSliderWidgetOptions);
search.addWidget(widget);

Options

RangeSliderWidgetOptions

  • containerstring|HTMLElement

    CSS Selector or DOMElement to insert the widget.

  • attributestring

    Name of the attribute for faceting.

  • tooltips[boolean|RangeSliderTooltipOptions]
    Default value: true

    Should we show tooltips or not. The default tooltip will show the raw value. You can also provide an object with a format function as an attribute. So that you can format the tooltip display value as you want

  • cssClasses[RangeSliderCssClasses]

    CSS classes to add to the wrapping elements.

  • pips[boolean]
    Default value: true

    Show slider pips.

  • precision[number]
    Default value: 0

    Number of digits after decimal point to use.

  • step[number]

    Every handle move will jump that number of steps.

  • min[number]

    Minimal slider value, default to automatically computed from the result set.

  • max[number]

    Maximal slider value, defaults to automatically computed from the result set.

RangeSliderTooltipOptions

  • format(number) => string

    The function takes the raw value as input, and should return a string for the label that should be used for this value. format: function(rawValue) {return '$' + Math.round(rawValue).toLocaleString()}

RangeSliderCssClasses

  • root[string|Array<string>]

    CSS class to add to the root element.

  • disabledRoot[string|Array<string>]

    CSS class to add to the disabled root element.

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.rangeSlider({
    container: '#price',
    attribute: 'price',
    tooltips: {
      format: function(rawValue) {
        return '$' + Math.round(rawValue).toLocaleString();
      }
    }
  })
);

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