Coveo for Sitecore keep page size when returning to results
When a user searches, changes the page size, clicks on a result, and then hits the back button to return to the search results, the page size is reset to the default.
Is there any way to persist the page size?
The ResultsPerPage component does not allow this functionality.
But it is not impossible to do. I see two options for you, both applying the same principles:
- Forking the repository
- Creating a simple extension
If you have a look at how the Pager component handles its state, it adds an event handler on the model with:
this.bind.onQueryState(MODELEVENTS.CHANGEONE, QUERYSTATEATTRIBUTES.FIRST, (data: IAttributeChangedEventArg) => this.handleQueryStateModelChanged(data) );
And then changes the state inside the component to handle this change.
You could create a new attribute that would handle the results per page, say
This attribute needs to be registered in the
QueryStateModel and can be done in the component's constructor:
const defaultAttributeValue = this.getInitialChoice(); this.queryStateModel.registerNewAttribute("rpp", defaultAttributeValue);
Then you can listen to this attribute using
rpp instead of
QUERY_STATE_ATTRIBUTES.FIRST in the first code block:
this.bind.onQueryState(MODELEVENTS.CHANGEONE, "rpp", …)
handleQueryStateModelChanged method, you can then use the attribute value to set the
You would also need to update the query state when the new value is selected:
If you go the extension way, the steps have to be executed using only public methods from the library.
You would need to register the attribute in a beforeInitialization event to ensure that the Search Interface understands your new attribute.
And then use a similar event handler to detect changes in the model for the
You could also read the hash on page load, extract the
rpp value and call
setResultsPerPage directly on your
And maybe use a
querySuccess event to get back the current results per page and set it back in the state.
Let me know if you decided to implement it!
The `2.4710.19` version now includes the change described in my previous answer.
Instead of step 5 in the `Switching Between the CDN and Local Files` tutorial, change the `CDN version` attribute to `2.4710` and it will automatically use the latest hotfix for this version.