CurrentRefinements connector provides the logic to build a widget that will give the user the ability to see all the currently applied filters and, remove some or all of them.
This provides a refine(item)
function to remove a selected refinement.
Those functions can see their behaviour change based on the widget options used.
const search= instantsearch(/* parameters */);
const makeCurrentRefinements= instantsearch.connectors.connectCurrentRefinements(
function renderFn(
renderOpts: CurrentRefinementsRenderingOptions,
isFirstRendering: boolean) {
// render the custom CurrentRefinements widget
}
);
const customCurrentRefinements = makeCurrentRefinements(instanceOpts: CustomCurrentRefinementsWidgetOptions);
search.addWidget(customCurrentRefinements);
(item) => undefined
Clears a single refinement
(item) => string
Creates an individual URL where a single refinement is cleared
Array<RefinementItem>
All the refinement items
Object
All original CustomCurrentRefinementsWidgetOptions
forwarded to the renderFn
.
string
The attribute on which the refinement is applied
function
The function to remove the refinement
Array<Refinement>
The current refinements
"facet"|"exclude"|"disjunctive"|"hierarchical"|"numeric"|"query"
The type of the refinement
string
The attribute on which the refinement is applied
string
The label of the refinement to display
string
The raw value of the refinement
[string]
The value of the operator, only if applicable
[boolean]
Whether the count is exhaustive, only if applicable
[number]
number of items found, if applicable
[Array<string>]
The attributes to include in the refinements (all by default). Cannot be used with excludedAttributes
.
[Array<string>]
["query"]
The attributes to exclude from the refinements. Cannot be used with includedAttributes
.
[(Array<object>) => Array<object>]
Function to transform the items passed to the templates.
// custom `renderFn` to render the custom ClearRefinements widget
function renderFn(currentRefinementsRenderingOptions, isFirstRendering) {
var containerNode = currentRefinementsRenderingOptions.widgetParams.containerNode;
if (isFirstRendering) {
containerNode
.html('<ul id="refinements"></ul><div id="cta-container"></div>');
}
containerNode
.find('#cta-container > a')
.off('click');
containerNode
.find('li > a')
.each(function() { $(this).off('click') });
if (currentRefinementsRenderingOptions.items
&& currentRefinementsRenderingOptions.items.length > 0) {
var list = currentRefinementsRenderingOptions.items.map(function(item) {
return '<li>' + item.attribute +
'<ul>' +
item.refinements.map(function (refinement) {
return <a href="' + currentRefinementsRenderingOptions.createURL(refinement) + '" data-attribute="' + item.attribute + '">'
+ refinement.label + '</a>'
}).join('') +
'</ul>'
'</li>';
});
currentRefinementsRenderingOptions.find('ul').html(list);
} else {
containerNode.find('#cta-container').html('');
containerNode.find('ul').html('');
}
}
// connect `renderFn` to CurrentRefinements logic
var customCurrentRefinements = instantsearch.connectors.connectCurrentRefinements(renderFn);
// mount widget on the page
search.addWidget(
customCurrentRefinements({
containerNode: $('#custom-crv-container'),
})
);
Can't find what you are looking for? Open an issue, we'll get back to you.