SharePoint 2013 : 'Scroll to Top Search Result Page' OOTB functionality has stopped working

Problem / Situation

'Scroll to Top Search Result Page' OOTB functionality stopped working on search result page.
We have enterprise search center with customized branding (master page and page layout).

Analysis

  • In search result web part checked the property "ScrollToTopOnRedraw" (after export search result web part) and it is set to 'True' (default).
  • Tried the solution described in blog but no success in hand
  • Now we have analyzed that this could be a problem of our customization in search template

Solution

  1. Export search result web part and set “ScrollToTopOnRedraw” property option to true

  2. Update search result display template "Control_SearchResults.html" template and add “ctx.ClientControl.set_scrollToTopOnRedraw(true)” function at the top of Srch.U.shouldAnimate(ctx.DataProvider)) if condition.

    <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()); };
    }
    
  3. If step 2 not worked for you then use JavaScript "window.scrollTo(0, 0);" method rather on place of "ctx.ClientControl.set_scrollToTopOnRedraw(true)" function.

  4. <div id="Control_SearchResults">
    <!--#_ //JS method for scroll to top issue
    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()); 
    };
    }