1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Reset all active refinements with the clearRefinements Instantsearch JS widget

    Raphael TerrierRaphael Terrier
    algoliaAlgolia

    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.

    Code

    Code

    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
    Transcript

    Transcript

    Instructor: 00:00 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.

    00:28 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.

    00:49 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.

    Discuss

    Discuss