Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Display Image Based on Field Value

$
0
0

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'>";
     }  
 
}


Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>