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

Novice attempting to use JS Link to render row color

$
0
0

Please forgive me in advance as I'm new to javascript and SharePoint development.

I've stitched together some code in an attempt to change the full row color of a display list.  The column that I'm looking to change is [Status].  I have successfully changed a single column background color, but would like to learn how to do this with and entire row.  As my column has three possible values, I have attempted to use the switch statement.  I referenced "http://www.codeproject.com/Articles/620110/SharePoint-Client-Side-Rendering-List-Views" in an attempt to get started.

1. I created a js file in Sublime text as shown below and posted

PClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPostRender: function(ctx) {
         var rows = ctx.ListData.Row;
         for (var i=0;i<rows.length;i++)

        var Status = rows[i]["Status"]
        switch (Status) {
        case "Delivered and Accepted":
                 {
                var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
                var tr = document.getElementById(rowElementId);
                tr.style.backgroundColor = "#008000";
                  };
                break;
        case "Shipped":
                {
                var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
                var tr = document.getElementById(rowElementId);
                tr.style.backgroundColor = "#ADFF2F";
                  };
                break;
        case "In Production":
                {
                var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
                var tr = document.getElementById(rowElementId);
                tr.style.backgroundColor = "#FFFF00";
                  };
        }

});

Followed proper procedure for loading the file in the site root, then adding the appropriate JS Link as I did when using the code that formats only the [Status] column.  No joy.


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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