Bit stumped on this one, wonder if anyone can help?
I've created some JavaScript which is stored in the Style Library and referenced by the JSLink property of a site column. When I navigate to a document library that includes the site column in its default view, the JSLink code does not appear to fire (tested using the line that writes to the console).
When I refresh the page however, the JSLink code fires and the image link is rendered for each item in the view. Why doesn't this code fire on the initial page load, but only on page refreshes?
(function () {
var overrideCtx = {};
overrideCtx.Templates = {};
overrideCtx.Templates.Fields = {
'SiteColumnInternalName': {
'View': function (ctx) {
// write to the console so we know whether or not the render code has run
if (console != undefined) console.log("Render code hit");
return "<a href='" + ctx.HttpRoot + "/_layouts/somefolder/somepage.aspx?List=" +
ctx.listName.replace('{', '').replace('}', '') + "&ID=" + ctx.CurrentItem.ID + "'>" +
"<img src='" + ctx.HttpRoot + "/Style%20Library/img/someimage.gif'/>" +
"</a>";
}
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCtx);})();