//Register for MDS enabled site otherwise the display template doesn't work on refresh
RegisterModuleInit("/_catalogs/masterpage/display templates/csr_ovr_TNDeskList.js", RegisterDeskList); // CSR-override for MDS enabled site
RegisterDeskList(); //CSR-override for MDS disabled site (because we need to call the entry point function in this case whereas it is not needed for anonymous functions)
function RegisterDeskList () {
/*
* Initialize the variable that store the overrides objects.
*/
var overrideCtx = {};
overrideCtx.Templates = {};
// Assign functions or plain html strings to the templateset objects:
// header, footer and item.
overrideCtx.Templates.Header = "Overridden
<#=ctx.ListTitle#>
";
overrideCtx.Templates.Footer = "
Footer";
// This template is assigned to the CustomItem function.
overrideCtx.Templates.Item = CustomItem;
overrideCtx.BaseViewID = 99; //Note: This is the BaseViewID we'll set when the renderlistview is called.
overrideCtx.ListTemplateType = 100;
// Now override the RenderListView once the ClientTemplates.JS has been called
ExecuteOrDelayUntilScriptLoaded(function(){
//Take a copy of the existing Microsoft Definition of RenderListView
var oldRenderListView = RenderListView;
//Now redefine RenderListView with our override
RenderListView = function(ctx,webPartID)
{
//Check the context of the currently rendering List view
if (ctx.ListTitle == "Desk List")
{
//Override the BaseViewID if it's the one we want.
ctx.BaseViewID = 99;
}
//now call the original RenderListView with the updated ctx object if applicable
oldRenderListView(ctx,webPartID);
}
},"ClientTemplates.js");
//Register the template overrides.
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);
};
/*
* This function builds the output for the item template.
* Uses the Context object to access announcement data.
*/
function CustomItem(ctx) {
// Build a listitem entry for every entry in the list.
var ret = "" + ctx.CurrentItem.Title + "";
return ret;
}