1

I've found various methods to return the default values for the field template override, including lookup, but I have been unable to find or successfully implement a method to do the same for fields in a Item Template that are not simply text (i.e. Lookup, People and Groups, etc...). In my code below, I would like to have the lookup field (ctx.CurrentItem.solSiteActSitesStatus) render as it normally would, as a modal dialog link to the item, in OTB list views. With this code, I get [object Object].

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function () {
function init() {
    SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
        Templates: {
            Item: function (ctx) {
                var varItemTitle = ctx.CurrentItem.Title;
                var varSiteLocStatus = ctx.CurrentItem.solSiteActSitesStatus;
                varSiteLocHtml = "<tr class=\"ms-itmHoverEnabled ms-itmhover\" role=\"row\">" +
                    "<td height=\"100%\" class=\"ms-cellstyle ms-vb-title\" colspan=\"99\">" +
                    "<div title=\"Item Details\" style=\"cursor:pointer;\" class=\"link-set\"><div>" + varItemTitle +
                    "</div><div>Status: " + varSiteLocStatus +
                    "</div></div></td></tr>";
                return varSiteLocHtml;
            }
        }
    });
}
RegisterModuleInit(SPClientTemplates.Utility.ReplaceUrlTokens("~site/SiteAssets/js/kdeReqSiteLocItemCSR-TESTING2.js"), init);
init();

});

2

You could try (ensure that the column name is in quotes)

var varSiteLocStatus = ctx.RenderFieldByName(ctx, "solSiteActSitesStatus");

Check out this article and scroll down to the section on "calling nested templates." The ctx object provides access to the all the different rendering methods used by SharePoint, so for any particular level you should be able to get the default HTML generated by SharePoint.

  • Put that column name in quotes and this works perfectly. Like this: ctx.RenderFieldByName(ctx, "solSiteActSitesStatus"), thanks! – Arknev Jun 1 '15 at 11:54
  • Doh!! Can't believe I forgot quotes... thanks for the edit! – Dylan Cristy Jun 1 '15 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.