The only decent blogs mentioning CSR and Grouping are:
- http://www.codeproject.com/Articles/620110/SharePoint-Client-Side-Rendering-List-Views (must read)
- http://jsuhail.blogspot.nl/2014/09/client-side-rendering-using-jslink-post_30.html
- Using JSLink to manage and output list groups and items
But neither solve the issue I have
CSR code also affects the Grouping display
I have CSR code which displays a standard Choice Column 'ratingBusiness' with options 0,1,2,3,4,5 as:
Users can change the ratingBusiness Number Value straight from the List View.
As you can see, Issue is that same CSR code is also applied to the Group By header.
Adding grouping with CSR
I can overrule the CSR Grouping with
FieldContext.Templates.Group =
function(ctx, group, groupId, listItem, listSchema, level, expand){
return '<div style="font-weight:bold">' + listItem[group] + '</div>';
};
But then more issues occur:
- Now all Group By ratingBusiness Number values are displayed at the top of the list
- all UX to collapse/uncollapse is gone.
Is it possible at all to retain the standard Number display in the Grouping headers?
The CSR function to display ratingBusiness in the Group By header is called once (with the first List Item as data), but at first sight I see no indication whether the code was called to display the item code or the Group By header code.
Workaround
I now created a Calculated Column referencing rateBusiness and use that to Group By. This gets me the (standard) Group By I am after.
But.. I have plenty more rating Columns, so then need an extra Calculated Column for every rating Column :-/
TIA
Danny
Update #1
If I set Group By COLLAPSED:
The ctx.CurrentItem object will not contain the CurrentItem data but only the groupheading info:
{
firstRow: true,
ratingBusiness: "5",
ratingBusiness.COUNT.group: "53",
ratingBusiness.groupindex: "1_",
ratingBusiness.newgroup: "1",
ratingBusiness.urlencoded: "%3B%235%3B%23"
}
So I can 'catch' the display in the Group heading with:
if (!CurrentItem.hasOwnProperty('ID')) { //not a ListItem
return CurrentItem[CurrentFieldSchema.Name];
}
Set to Group By EXPAND and ctx.CurrentItem will always contain the first CurrentItem