The refinementList widget displays a list of facet values that users can select to filter results. It’s one of the most common filtering widgets, supporting multi-selection and search within facets.
Usage
const refinementList = instantsearch . widgets . refinementList ({
container: '#brand-list' ,
attribute: 'brand' ,
});
search . addWidget ( refinementList );
Examples
Basic Refinement List
instantsearch . widgets . refinementList ({
container: '#categories' ,
attribute: 'categories' ,
limit: 10 ,
});
With Search for Facet Values
instantsearch . widgets . refinementList ({
container: '#brands' ,
attribute: 'brand' ,
searchable: true ,
searchablePlaceholder: 'Search brands...' ,
limit: 5 ,
showMore: true ,
showMoreLimit: 20 ,
});
With OR/AND Operator
// OR operator (default) - shows results matching ANY selected value
instantsearch . widgets . refinementList ({
container: '#categories' ,
attribute: 'categories' ,
operator: 'or' ,
});
// AND operator - shows results matching ALL selected values
instantsearch . widgets . refinementList ({
container: '#features' ,
attribute: 'features' ,
operator: 'and' ,
});
With Custom Sorting
instantsearch . widgets . refinementList ({
container: '#brands' ,
attribute: 'brand' ,
sortBy: [ 'isRefined' , 'count:desc' , 'name:asc' ],
});
Options
container
string | HTMLElement
required
CSS Selector or HTMLElement to insert the widget.
The name of the attribute in your records. Must be declared as an attribute for faceting in your Algolia settings.
operator
'or' | 'and'
default: "'or'"
How to apply multiple selections:
'or': Show results matching ANY selected value
'and': Show results matching ALL selected values
Maximum number of facet values to display.
Whether to display a “Show more” button.
Maximum number of facet values to display when “Show more” is clicked.
sortBy
string[] | function
default: "['isRefined', 'count:desc', 'name:asc']"
How to sort refinements. Can be an array of strings or a sorting function. Available string values:
'isRefined' - Refined values first
'count:asc' - By count ascending
'count:desc' - By count descending
'name:asc' - Alphabetically ascending
'name:desc' - Alphabetically descending
Add a search input to filter facet values. Requires the attribute to be searchable for faceting.
searchablePlaceholder
string
default: "'Search...'"
Placeholder text for the search input.
If false, the search input is disabled when there are fewer items than the limit.
searchableEscapeFacetValues
Whether to escape facet values in the search results.
Function to transform the items before rendering. ( items : object []) => object []
Templates to customize the widget rendering. Template for each facet value item.
Template for the “Show more” button.
Template displayed when search returns no results.
CSS classes to add to the widget elements. CSS class for the root element.
CSS class when no refinements are available.
CSS class for the list element.
CSS class for selected items.
CSS class for the checkbox.
CSS class for the label text.
CSS class for the “Show more” button.
HTML Output
< div class = "ais-RefinementList" >
< div class = "ais-RefinementList-searchBox" >
<!-- SearchBox for facet values -->
</ div >
< ul class = "ais-RefinementList-list" >
< li class = "ais-RefinementList-item ais-RefinementList-item--selected" >
< label class = "ais-RefinementList-label" >
< input class = "ais-RefinementList-checkbox" type = "checkbox" checked />
< span class = "ais-RefinementList-labelText" > Apple </ span >
< span class = "ais-RefinementList-count" > 746 </ span >
</ label >
</ li >
< li class = "ais-RefinementList-item" >
< label class = "ais-RefinementList-label" >
< input class = "ais-RefinementList-checkbox" type = "checkbox" />
< span class = "ais-RefinementList-labelText" > Samsung </ span >
< span class = "ais-RefinementList-count" > 633 </ span >
</ label >
</ li >
</ ul >
< button class = "ais-RefinementList-showMore" > Show more </ button >
</ div >
Requirements
The attribute must be declared as an attribute for faceting in your Algolia index settings. For searchable faceting, the attribute must also be searchable for faceting .