At Work 03 : Scroll to top of the page after Pagination/Refinement/Search event in SharePoint 2013 search results

This post is about “ScrollToTopOnRedraw” property of search results webpart. The page scrolls to top after a search operation (search, refinment, pagination) if set to true. It is a boolean property which is false by default and All we need to do is set this boolean value to true for our search results webpart/ search context.

We can set this property in Two ways:

In Webpart properties:

1) Export your current search results webpart to get .webpart file

2) Open it in a text editor (VS)

3). Find the property “ScrollToTopOnRedraw” and change its value from False to True and Save the file.

4).Import the webpart and add it in your page.

Thats All. The page scrolls to top when you click on pagination links / apply refiners / apply search.

In Control template: 

This is the simplest way to achieve the scroll if you are using custom control display template for your search results.

The OOTB “Control_SearchResults.html” control template looks like

<div id="Control_SearchResults">
<!--#_
if (Srch.U.shouldAnimate(ctx.DataProvider)){
Srch.U.hideElement(ctx.ClientControl.get_element());
ctx.OnPostRender = function(){ Srch.U.animateResults(ctx.ClientControl, ctx.DataProvider.get_userAction()); };
}
_#-->

Add a line of code at the top of if condition to change the property value

<div id="Control_SearchResults">
<!--#_
//scroll to top on redraw(pagination, refiner, search)
ctx.ClientControl.set_scrollToTopOnRedraw(true);
if (Srch.U.shouldAnimate(ctx.DataProvider)){
Srch.U.hideElement(ctx.ClientControl.get_element());
ctx.OnPostRender = function(){ Srch.U.animateResults(ctx.ClientControl, ctx.DataProvider.get_userAction()); };
}
_#-->
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s