Gravatar for ravigupta020287@gmail.com

Question by Ravi, Dec 26, 2016 9:43 PM

Hierarchical Facet not expanding

I am using Coveo for sitecore 3.0 i tried the solution above My Code:

Coveo.$('#search').on('deferredQuerySuccess', function(e, args){ 
    var facet = Coveo.$('.CoveoHierarchicalFacet').coveo();
    var values = facet.values.getSelected();
    for(var i = 0; i < values.length; i++) { 
         facet.open(values[i]); 
    }
})

This above code is not working, but when i write the code in browser console and execute it, the facets are expanding as expected, also when switching between the tabs it is working.

What am i doing wrong here?

1 Reply
Gravatar for sbelzile@coveo.com

Answer by Sébastien Belzile, Dec 27, 2016 11:01 AM

  1. Is the code above "not working" or not being executed when you wish it to be executed?
  2. When do you expect this code to be executed?
  3. Do you think you are using the proper event? (deferredQuerySuccess vs querySuccess)
Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 28, 2016 12:20 AM

Yes the above code is not working as expected, but it is getting executed.

I want to execute the code after page load and after the execution of all JavaScript of coveo.

deferredQuerySuccess is the last event of Coveo JS, so i tried to execute my code inside this event but not getting the facets to expand.

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Dec 28, 2016 8:25 AM

Have you tried using:

$('.CoveoHierarchicalFacet').coveo('expandFacet');

instead? This must be placed in the same event (deferredQuerySuccess) and make sure enableCollapse is true for all facets.

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 28, 2016 11:29 AM

Yes i have tried that as well, it didn't work.

Gravatar for ravigupta020287@gmail.com

Comment by Ravi, Dec 28, 2016 10:29 PM

The code below doesn't work on page load, it works only when the user switch the tabs in the search page, it expand the selected facet group.

Coveo.$('#search').on('deferredQuerySuccess', function(e, args){ 
    var facet = Coveo.$('.CoveoHierarchicalFacet').coveo();
    var values = facet.values.getSelected();
    for(var i = 0; i < values.length; i++) { 
         facet.open(values[i]); 
    }
})
Gravatar for olamothe@coveo.com

Comment by olamothe, Jan 3, 2017 9:02 AM

Since it does not work on "page load", this probably means that your handler is bound "after" you call "init" on your search interface.

Ensure that the function is bound before you initialized the search interface, otherwise it won't work on the first query.

Ask a question