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

CSR and JSLink: Error After Filtering and Viewing/Editing Item

$
0
0

I have a *.js to color code my rows according to the value of the column 'Status'. It is working very fine UNLESS one filters any column and views/edits an item.
After exiting the item view, the following error occurs:
TypeError: Unable to get value of the property 'style': object is null or undefined

It seems that the last row (see my full code below) row.style.backgroundColor = statusColors[status];does cause the error. Is there any alternative to OnPostRender?

 

SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
  OnPostRender: function(ctx) {

	var statusColors =  {
		'Accepted' : '#ccff99',
		'Superseded' : '#ffb366',
		'Pending' : '#ffff66',
		'Delivered' : '#4bb84f',
		'Rejected' : '#ff6666'
    };

    var rows = ctx.ListData.Row;
    for (var i=0;i<rows.length;i++)
    {
        var status = rows[i]["Status"];
        var rowId = GenerateIIDForListItem(ctx, rows[i]);
        var row = document.getElementById(rowId);
        row.style.backgroundColor = statusColors[status];
    }
  }
});


Viewing all articles
Browse latest Browse all 7589

Trending Articles



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