I am trying to override the numberOfResults property in Coveo Search UI before initializing, but doesn't seem to take affect. What could I be doing wrong?

Coveo.$('#@Model.Id').on("buildingQuery", function(e, args) {
  args.queryBuilder.numberOfResults= 40;
  console.log(args.queryBuilder); //shows correct value of 40
}).coveoForSitecore("init", CoveoForSitecore.componentsOptions);

Incorrect value when sent to service call. Shows 20 instead of 40.

enter image description here

  • Is this page using a pager or infinite scroll? Commented Dec 19, 2016 at 18:36

1 Answer 1


Since the Pager listens to the buildingQuery event (according to this), it is probably the one overriding the query.

Try setting it in the doneBuildingQuery event instead.

Moreover, if you don't want a dynamic number of results and only want to set a result per page different from the OOTB offering, you can set it in the Coveo Search component properties with the Number of results per page property in the Paging section. It can also be set directly in the markup of the CoveoSearchInterface using data-results-per-page='10', but this approach that would require you to duplicate the search component since you are modifying the file and don't want your changes to be overridden.

Also, it might not be the case, but if you are trying to create your own ResultPerPage component, Coveo for Sitecore started bundling one OOTB with the 4.0.450 version.

Simply add this tag in your CoveoSearchInterface:

<div class="CoveoResultsPerPage"></div>
  • I am seeing this error if I try to tap onto doneBuildingQuery event Uncaught TypeError: Cannot read property 'addEventListener' of null at CoveoForSitecore.min.js:1. I do need to bring back dynamic number of results on the same result list.
    – xoail
    Commented Dec 19, 2016 at 16:13
  • Did you change something in your code? Only changing from buildingQuery to doneBuildingQuery should never throw a Cannot read property 'addEventListener' of null. Coveo.$('#@Model.Id') is somehow null now and unrelated to the initial problem. Commented Dec 19, 2016 at 16:17
  • This is what I added Coveo.$('#@Model.Id').on("doneBuildingQuery", function(e, args) { console.log("doneBuildingQuery");});. I also have buildingQuery event somewhere on the page. Not sure if having both of these is conflicting and causing issue.
    – xoail
    Commented Dec 19, 2016 at 16:20
  • Actually I am seeing the addEventListener error no matter if I add doneBuildingQuery or not. So it seems like an error exists for a while not sure why. But one thing is sure only buildingQuery event is getting triggered. newQuery or doneBuildingQuery do not execute.
    – xoail
    Commented Dec 19, 2016 at 16:38
  • 1
    Try storing Coveo.$('#@Model.Id') in a variable like so: var searchInterface = Coveo.$('#@Model.Id'); and then calling it multiple times: searchInterface.on("doneBuildingQuery", function() { ... }); searchInterface.on("buildingQuery", function() { ... }); searchInterface.coveoForSitecore("init", CoveoForSitecore.componentsOptions); Commented Dec 19, 2016 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.