Matches count in Numeric Menu

We can see that there are no count badges to the right of the options in the Numeric Menu:

How to add them?

Hi there,

I found this issue in the InstantSearch.js repository which should be relevant to your question.

TL;DR: This isn’t supported out of the box, but there are workarounds.

  • Precomputing the buckets and using that as a facet (assuming those buckets aren’t dynamic)
  • using connectRefinementList and sum the facets in each bucket from the front-end (assuming they don’t overlap)

I hope this helps!

1 Like

Thank you.

Currently as a workaround I have already taken the first path: adding another pre-computed attribute to the index. Also, I’ve just found the following question which complements your suggestion.

As to the second path, it also seems promising… Yet I’d choose connectMenu to get the radio button behavior according to the other discussion linked above.

I’ve tried the second path, and it works for rendering, but now I’m stuck at how to pass multiple values to the refine function when one of my buckets is selected. Any suggestion?

Actually I managed it to work by calling refine several times with different values:

However I’m not satisfied with the fact that the widget gets rendered several times with intermediate set of refined values. This is seen in the console.

I’m calling refine in a loop to toggle the facet values, and I expect Instantsearch to trigger the search asynchronously and only once after all the calls are done. Any idea on how to achieve the desired behavior?

Hi @anantakrishna.kem for that particular problem please look at my answer here: ttps://discourse.algolia.com/t/stop-refinementlist-sorting-hits-upon-selection/8848/12?u=youcef

1 Like

Yes, it turns out that creating a custom widget is the way to do it right.