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];
}
}
});