All,
In the following code I am using with a custom SharePoint 2013 list which I didn't create I'm attempting the following and have some questions for how to obtain the following:
1) The field name I am trying to get the value from is called IP % Comp which has spaces and a % - therefore how can I obtain this value from the var _statusValue = ctx.CurrentItem line
2) Based on the value from the IP % Comp field I'm trying to display an image but need that image displayed in it's own field.
(function () {
var statusFieldCtx = {};
statusFieldCtx.Templates = {};
statusFieldCtx.Templates.Fields = {
"IP % Comp": {
"View": StatusFieldViewTemplate
}
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
statusFieldCtx
);
})();
function StatusFieldViewTemplate(ctx) {
var _statusValue = ctx.CurrentItem.IP % Comp;
if (_statusValue == '100.0 %')
{
return "<img src='/Images/green.png'>";
}
if (_statusValue >= '50.0 %' && <= '99.9 %')
{
return "<img src='/Images/yellow.png'>";
}
if (_statusValue < '50.0 %')
{
return "<img src='/Images/red.png'>";
}
}