12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
11 : 17 : 24 : 39
Become a member
to unlock all features

    Reset all active refinements with the clearRefinements Instantsearch JS widget

    Raphael TerrierRaphael Terrier

    When performing a complex query, based on several active facets and filters, its tedious for the user to start from scratch if she has to unset all refinements one by one. Thanks to the clearAll widget, this task becomes a one click action for the user and is trivial to implement for us developers as it requires no configuration.



    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson




    Instructor: We need to provide an easy way for our users to reset their search refinements. That's the clearAll widget's mission. Extremely simple to add. The container in our HTML file first. Let's add it to the top of our refinement column on the left and give it an ID of clearAll. Then, in app.js, search, add widget, instantsearch, widgets, and clearAll.

    Configuring the container, the ID is clearAll. We refresh the page. Nothing changes yet. Then, if we refine on the brand facet, for instance, we now have a "Clear all" link that appears on top. Clicking it will clear all the active refinements.

    We can change the "Clear all" default string to add whatever we want. In templates link, let's add "Reset everything." Now, refining on a brand, the link displays "Reset everything" instead. Note that as the name implies, this widget clears all refinements, not only the facets, but also numerical values like the range input down there.