so I am currently using JSLink to change the look and feel of my List view, but am getting a little stuck in getting the HTML hierachy of my elements right.
This is my current code...
function ItemOverride(ctx) {
var listhtml = '<div class="listItemWrapper"><div class="vacancyListItemJobTitle">' + ctx.CurrentItem.Title + '</div></div>';
return listhtml;
}
function CustomGroup(ctx, group, groupId, listItem, listSchema, level, expand) {
var html = '<div class="vacancyRegionListHeader">' + listItem["VacancyRegion"][0].lookupValue.toUpperCase() + '</div>';
return html;
}
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Header = "<div id=\"vacancyList\">";
overrideCtx.Templates.Group = CustomGroup;
overrideCtx.Templates.Item = ItemOverride;
overrideCtx.Templates.Footer = "</div>";
overrideCtx.BaseViewID = 1;
overrideCtx.ListTemplateType = 100;
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
})();`
What this is giving me is something like..
<div class="vacancyRegionListHeader"></div>
<div class="listItemWrapper"></div>
<div class="vacancyRegionListHeader"></div>
<div class="listItemWrapper"></div>
<div class="listItemWrapper"></div>
<div class="vacancyRegionListHeader"></div>
<div class="listItemWrapper"></div>
but what Im looking for is something like the following output
<div class="vacancyRegionListHeader">
<div class="itemGroupWrapper">
<div class="listItemWrapper"></div>
</div>
</div>
<div class="vacancyRegionListHeader">
<div class="itemGroupWrapper">
<div class="listItemWrapper"></div>
<div class="listItemWrapper"></div>
</div>
</div>
<div class="vacancyRegionListHeader">
<div class="itemGroupWrapper">
<div class="listItemWrapper"></div>
</div>
</div>
As you can tell, I want all the items to be contained in a div container, under each group header container. Reason for this is because I am wanting to have a javascript function that, when a .vacancyRegionListHeader
is clicked, it collapses the whole next div item (which would be all the list items).
Currently my current implementation only collapses the first item under the header, and not all the items in the group.
How can I get the result using my JSLink functions?
From what i can tell, the code is first seeing the group then creates the header html. Then sees each item, and creates the HTML. Then sees another group, and creates the header HTML, etc. I don't know how to generate the ItemOverride function within a group override. Or at least create some sort of group 'groupHeader'-listItems-'groupFooter' type thing.
any ideas?
Thanks!
itemGroupWrapper
divs coming from? I don't see them in your code. Is that the SP default group rendering? Are you just wanting to wrap the SP default group rendering with another div?itemGroupWrapper
div is not in my code yet, but a div I want to somehow put in, just not sure how. So Im wanting to wrap all listItems into the groupWrapper, under a ListHeader