Scroll to Top Search Result Page

Scroll to Top Search Result Page” issue encounter while working with one of our client. Client has customized 2013 search center with branding (that includes all custom master page and layout pages) and because of this customization the scroll to top “OOB” functionality stop working.

I have search a lot but only find one blog related to this issue, I need to must say thanks to this post help me to investigate on it.

As per this blog you can enable this two ways.
  • Web Part property to set “ScrollToTopOnRedraw” option to true. ( I checked by default it true for our ‘.webpart’ webpart.
  • Update OOB Control template “Control_SearchResults.html” template and put “ctx.ClientControl.set_scrollToTopOnRedraw(true)” function at the top of Srch.U.shouldAnimate(ctx.DataProvider))condition. Below is the code snippets. 
<div id="Control_SearchResults">
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()); };
}
I have checked both options but it not working at my end. I did slight modify the template code. I used the javascript “window.scrollTo(0, 0);”method rather than OOB “ctx.ClientControl.set_scrollToTopOnRedraw(true)” function and its works for me.

Here is the actual code that works for me.

<div id="Control_SearchResults">
<!--#_ //scroll to top 
window.scrollTo(0, 0); 
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()); 
};
}

Comments

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

Types of Features in SharePoint 2013

Send Email using SharePoint Rest API