the code in the control display template uses _#= ctx.RenderGroups(ctx) =#_ and there is another JS file named group_content.js that is being called, how do i split my data into groups in order to render some HTML per group?
Sharepoint Display Templates How to use Group Display Template
753 Views Asked by bresleveloper At
2
There are 2 best solutions below
0
On
As completing your answer, I think the beauty of using ctx.ListData[ctx.ListDataJSONGroupsKey] array is using different group and item display templates for each Group. Watching this array using developer tools shows an array of objects in the following form:
GroupTemplateId: null
ItemTemplateId: null
Properties: {GenerationId: 9223372036854776000, indexSystem: "", ExecutionTimeMs: 63, QueryModification: "path:"https://modernsharepointexperiences.sharepoi…tItem") -ContentClass=urn:content-class:SPSPeople", RenderTemplateId: "~sitecollection/_catalogs/masterpage/Display Templates/Search/Group_Default.js", …}
QueryId: "ca540784-162f-4a9e-9ad4-da45e615ca06"
QueryRuleId: "00000000-0000-0000-0000-000000000000"
ResultRows: (10) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
ResultTitle: null
ResultTitleUrl: null
RowCount: 10
TableType: "RelevantResults"
TotalRows: 10
TotalRowsIncludingDuplicates: 31
_ObjectType_: "Microsoft.SharePoint.Client.Search.Query.ResultTable"
Here, I think, we can set Group Display Template and Item Display Template for each element of above array (really each group). Please correct me if you think I am wrong! Thanks
After intensive research, you need to do some manually to use it.
Create Group Display Template file, just take the default "group_xxx.html" from the "Search" or "Content Search" Folders, whatever you are using.
MUST download a copy or you Search WebPart (export) and change the value in "GroupTemplateId" to your group JS file.
CODING objects to mimic
ResultTablesobjectfinal code
read more here