Search Control Template with page size drop down

In OOB control template there is only 10 results per result able to view to the end user. The functionality would be handy if we provide such type of end user to change the result size itself.   



So the idea just place on drop-down at the top of the search result, when user changes the drop down it will change the size of the page.

To implement, we would require change the “Control_SearchResults.html” template only




Following are the steps to implement drop down in Control Search results.
  • Navigate to the search center
  • Map “<server:Port>\_catalogs\masterpage\Display Templates\Search”.
  • Edit Control_SearchResults.html template.
  • Look for <div id="Control_SearchResults"> div at the top of the div placed the below mentioned code.
<!--#_
Type.registerNamespace('search.Results');
search.Results = function() {
return {
loadMoreResults: function (value) {
// Loading more results
ctx.DataProvider.set_resultsPerPage(value);
ctx.DataProvider.issueQuery();
}
}
}();

Srch.U.registerRenderTemplateByName("loadmoreresults", search.Results.loadMoreResults);
_#-->             
<select  id="resultsPerPageSelect" onchange="Srch.U.getRenderTemplateCollection().loadmoreresults(this.value);" >
<!--#_
for (var i = 10; i <= 50; i=i+10) {
var lang = ctx.DataProvider.get_resultsPerPage();
if(lang == i) {
_#-->
<option selected="selected" value="_#= $htmlEncode(i) =#_">
_#= $htmlEncode(i) =#_
</option>
<!--#_
} else {
_#-->
<option value="_#= $htmlEncode(i) =#_">
_#= $htmlEncode(i) =#_
</option>
<!--#_
}
}
_#-->
</select>

  • Save the template
  • Publish the page from UI.

Sample Template

The Sample template is available here: Control_SearchResults.html(GitHub)



Comments

Popular posts from this blog

SharePoint RPC Protocols Examples Using OWSSVR.DLL

Send Email using SharePoint Rest API

Query suggestions in SP 2013 Using Rest API (/_api/search/suggest)