javascriptnext.jssitecorejss

I want to convert sitecore search facet filter from multiple to single


I am trying to implement sitecore search widget and result list is working properly as expected.

I tried filter functionality using facet and by default it is multiple filter functionality.

but as per my requirement i want single select (single facet at time)

I tried but not sure how to archive this functionality. Please help me out.

I tried this but it is not supporting single check It is adding new selected facet id into that array I want to remove previous and add latest

<button onClick={() => { onFacetClick({ facetValueId: selectedArticleTypeValue?.id, facetIndex: 0, facetId: 'article_type', type: 'valueId', checked: false, }); > {jobFacet?.text} </button>


Solution

  • This will not work this way,

    As per my understanding it is only support multiple filter in facet. so you have to right custom logic for this what can you do

    1. manage one state for selectedFacet
    2. OnClick of button add logic to call this onFacetClick as well as manage that state as well
    3. also add condition that if there is already selectedFacet (that you will find through state) then remove first one and then add latest

    Something like this

    if (selectedValue) {
                                        onFacetClick({
                                          facetValueId: selectedArticleTypeValue?.id,
                                          facetIndex: 0,
                                          facetId: 'article_type',
                                          type: 'valueId',
                                          checked: false,
                                        });
                                      }
                                      if (jobFacet.id) {
                                        onFacetClick({
                                          facetValueId: jobFacet.id,
                                          facetIndex: 0,
                                          facetId: 'article_type',
                                          type: 'valueId',
                                          checked: true,
                                        });
                                      }