Signature
Import
About this widget
ThecurrentRefinements
widget displays a list of refinements applied to the search.
Examples
JavaScript
Options
The CSS Selector or
HTMLElement
to insert the widget into.The attributes to include in the widget (all by default).
Cannot be used with
excludedAttributes
.
In the example below, only the categories
attribute is included in the widget.JavaScript
The attributes to exclude from the widget. Cannot be used with
includedAttributes
. In the example below, the brand
attribute is excluded from the widget.JavaScript
The CSS classes you can override:
root
. The root element of the widget.noRefinementRoot
. The root element if there are no refinements.list
. The list element.item
. The list items.label
. The label element of each item.category
. The container of each item value.categoryLabel
. The text element of each item value.delete
. The button element of eatch item value.
JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript
HTML output
HTML
Customize the UI with connectCurrentRefinements
If you want to create your own UI of the currentRefinements
widget, you can use connectors.
To use connectCurrentRefinements
, you can import it with the declaration relevant to how you installed InstantSearch.js.
JavaScript
Create a render function
This rendering function is called before the first search (init
lifecycle step)
and each time results come back from Algolia (render
lifecycle step).
JavaScript
Rendering options
All the currently refined items, grouped by attribute.With each item:
indexName: string
. The index name on which the refinement is applied.indexId: string
. The index id on which the refinement is applied.attribute: string
. The attribute on which the refinement is applied.label: string
. The textual representation of this attribute.refine: function
. Removes the refinement.refinements: object[]
. Currently applied refinements.
type: 'facet' | 'exclude' | 'disjunctive' | 'hierarchical' | 'numeric' | 'query'
. The type of the refinement.attribute: string
. The attribute on which the refinement is applied.label: string
. The label of the refinement to display.value: string
. The raw value of the refinement.operator?: string
. The value of the operator (only if applicable).exhaustive?: boolean
. Whether the count is exhaustive (only if applicable).count?: number
. The number of found items (only if applicable).
JavaScript
Indicates if search state can be refined.
JavaScript
Clears a single refinement and triggers a new search.
JavaScript
Generates a URL for the next state.
JavaScript
All original widget options forwarded to the render function.
JavaScript
Create and instantiate the custom widget
First, create your custom widgets using a rendering function. Then, instantiate them with parameters. There are two kinds of parameters you can pass:- Instance parameters. Predefined options that configure Algolia’s behavior.
- Custom parameters. Parameters you define to make the widget reusable and adaptable.
renderFunction
, both instance and custom parameters are accessible through connector.widgetParams
.
JavaScript
Instance options
The attributes to include in the widget (all by default).
Cannot be used with
excludedAttributes
.
In the example below, only the categories
attribute is included in the widget.JavaScript
The attributes to exclude from the widget.
Cannot be used with
includedAttributes
.
In the example below, the brand
attribute is excluded from the widget.JavaScript
A function that receives the list of items before they are displayed.
It should return a new array with the same structure.
Use this to transform, filter, or reorder the items.The function also has access to the full
results
data,
including all standard response parameters
and parameters from the helper,
such as disjunctiveFacetsRefinements
.JavaScript