Created
December 3, 2014 08:20
-
-
Save estruyf/b4986935fc522f6dfac2 to your computer and use it in GitHub Desktop.
SPSUK Demo Grouping (Control template)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"> | |
<head> | |
<title>Grouping Template</title> | |
<!--[if gte mso 9]><xml> | |
<mso:CustomDocumentProperties> | |
<mso:TemplateHidden msdt:dt="string">0</mso:TemplateHidden> | |
<mso:MasterPageDescription msdt:dt="string"></mso:MasterPageDescription> | |
<mso:ContentTypeId msdt:dt="string">0x0101002039C03B61C64EC4A04F5361F385106601</mso:ContentTypeId> | |
<mso:TargetControlType msdt:dt="string">;#Content Web Parts;#</mso:TargetControlType> | |
<mso:HtmlDesignAssociated msdt:dt="string">1</mso:HtmlDesignAssociated> | |
<mso:HtmlDesignConversionSucceeded msdt:dt="string">True</mso:HtmlDesignConversionSucceeded> | |
<mso:HtmlDesignStatusAndPreview msdt:dt="string">http://intranet/sites/SPSUK/_catalogs/masterpage/SPSUK/Grouping/Control_Group.html, Conversion successful.</mso:HtmlDesignStatusAndPreview> | |
</mso:CustomDocumentProperties> | |
</xml><![endif]--> | |
</head> | |
<body> | |
<script> | |
$includeCSS(this.url, "~sitecollection/_catalogs/masterpage/SPSUK/Grouping/style.css"); | |
Type.registerNamespace('search.Grouping'); | |
search.Grouping = function() { | |
var currentCtx; | |
return { | |
init: function (currentContext, encodedId) { | |
currentCtx = currentContext; | |
// Creating a new grouping object | |
currentCtx.Grouping = {}; | |
// Add an on post render callback, this will be excuted when all the results are rendered | |
AddPostRenderCallback(currentContext, function() { | |
var groupElm = document.getElementById(encodedId); | |
search.Grouping.show(groupElm); | |
}); | |
}, | |
push: function (grouping, content) { | |
// Add the markup to the grouping array | |
if (typeof currentCtx.Grouping[grouping] !== "undefined") { | |
currentCtx.Grouping[grouping] += content; | |
} else { | |
currentCtx.Grouping[grouping] = content; | |
} | |
}, | |
show: function (groupElm) { | |
var groups = currentCtx.Grouping | |
// Add the content to the page | |
for (var key in groups) { | |
groupElm.innerHTML += String.format("<div class='group'><h2 style='color:#000'>{0}</h2>{1}</div>", key, groups[key]); | |
} | |
} | |
} | |
}(); | |
Srch.U.registerRenderTemplateByName("group_init", search.Grouping.init); | |
Srch.U.registerRenderTemplateByName("group_push", search.Grouping.push); | |
Srch.U.registerRenderTemplateByName("group_show", search.Grouping.show); | |
</script> | |
<div id="Control_List"> | |
<!--#_ | |
var encodedId = $htmlEncode(ctx.ClientControl.get_nextUniqueId() + "_Grouping"); | |
// Grouping init | |
Srch.U.getRenderTemplateCollection().group_init(ctx, encodedId); | |
if (!$isNull(ctx.ClientControl) && | |
!$isNull(ctx.ClientControl.shouldRenderControl) && | |
!ctx.ClientControl.shouldRenderControl()) | |
{ | |
return ""; | |
} | |
ctx.ListDataJSONGroupsKey = "ResultTables"; | |
_#--> | |
<div id="_#= encodedId =#_"> | |
_#= ctx.RenderGroups(ctx) =#_ | |
</div> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment