I am building a complex filtering system for a client that requires multiple fs-cmsfilter-element=“results-count” elements on the same page for the same collection list.
Currently there is only 1 of my 3 elements that shows the correct number, the other 2 don’t work, meaning their number is just static.
It would be awesome if you could help me out on this
Thank you in advance!
Hey @Simon_Lampert! Can you please share your links?
Hey Luis, thank you for getting back to me.
I sent you the preview link in a private message since it shouldn’t be visible to the public
Can anyone share solution here?
hey @Taabish! Sure!
For several result counts for one filter instance, you can try using something like this code that retrieves the results from the CMS Filter API instead of the fs-cmsfilter-element = results-count
<script>
window.fsAttributes = window.fsAttributes || [];
window.fsAttributes.push([
'cmsfilter',
(filterInstances) => {
console.log('cmsfilter Successfully loaded!');
// The callback passes a `filterInstances` array with all the `CMSFilters` instances on the page.
const [filterInstance] = filterInstances;
let filterResult = filterInstance.resultsElement.innerHTML;
const resultsNumber = document.querySelectorAll('.results-text'); // This is the class for all your result count text elements
resultsNumber.forEach((result) => {
result.innerHTML = filterResult;
});
// The `renderitems` event runs whenever the list renders items after filtering.
filterInstance.listInstance.on('renderitems', (renderedItems) => {
filterResult = filterInstance.resultsElement.innerHTML;
resultsNumber.forEach((result) => {
result.innerHTML = filterResult;
});
});
},
]);
</script>
2 Likes
Thank you @Support-Luis for this code,
Can we show results counts for each category results ?
For example - Category A has 5 results, Category B has 4, and so on.
Refer attached image for understanding
1 Like
Hey @Taabish! This should handle the results count for each category. Can you share your page if this does not work on your end?