Hey Guys, I’m trying to make my filters be initial...
# community-help
d
Hey Guys, I’m trying to make my filters be initially selected according to the initial query or actually the initial selected value: So suppose if I have my initial query to be search collection and i want to filter by category (facet) I would like the widgets - refinementList, starRating, currentRefinements all to be pre-populated with the currently selected category. I was looking for a way of doing this without having to transformItems on each widget and them to be automatically updated. Is this something that can be done ?
Copy code
instantsearch({
            searchClient,
            indexName: defaultIndex,
            searchFunction(helper) {
                if (catFilter !== undefined && catFilter !== '') {
                    helper.addDisjunctiveFacetRefinement('category', catFilter).search();
                    catFilter = '';
                } else {
                    helper.search();
                }
            }
        });
Update was able to do this by using searchFunction and DisjunctiveFaceRefienement
j
Nice, thanks for sharing!
Question: how is
catFilter
populated?
d
catFilter is the initial value sent as a data attribute in the wrapper. So data-cat=“tshirts” and then on iniital load we get that value to filter by category
👍 1