Reset all active refinements with the clearRefinements Instantsearch JS widget

Raphael Terrier
InstructorRaphael Terrier
Share this video with your friends

Social Share Links

Send Tweet
Published 6 years ago
Updated 3 years ago

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.

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.

egghead
egghead
~ 5 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today