I've added a list view webpart onto a SharePoint 2013 online page, this webpart has a JS Link to a file containing JavaScript which applies different CSS to the CurrentRiskImpactLikelihood column depending on it's value.
The JavaScript i've used is below:
(function () {
var condFieldCtx = {};
condFieldCtx.Templates = {};
condFieldCtx.Templates.Fields = {
"CurrentRiskImpactLikelihood": {"View": PriorityFormat1},
};
condFieldCtx.OnPostRender = [PriorityFormat1];
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(condFieldCtx);
})();
function PriorityFormat1(ctx){
var priorityValue = ctx.CurrentItem.CurrentRiskImpactLikelihood;
if(priorityValue == 'Very Low'){
return "<span><font style='padding:5px;color:black;background-color:yellow;display:block;'>"+ctx.CurrentItem.CurrentRiskImpactLikelihood+"</font></span>";
}
else if(priorityValue == 'Low'){
return "<span><font style='padding:5px;color:black;background-color:yellow;display:block;'>"+ctx.CurrentItem.CurrentRiskImpactLikelihood+"</font></span>";
}
else if(priorityValue == 'Medium'){
return "<span><font style='padding:5px;color:white;background-color:orange;display:block;'>"+ctx.CurrentItem.CurrentRiskImpactLikelihood+"</font></span>";
}
else if(priorityValue == 'High'){
return "<span><font style='padding:5px;color:white;background-color:red;display:block;'>"+ctx.CurrentItem.CurrentRiskImpactLikelihood+"</font></span>";
}
else if(priorityValue == 'Very High'){
return "<span><font style='padding:5px;color:white;background-color:red;display:block;'>"+ctx.CurrentItem.CurrentRiskImpactLikelihood+"</font></span>";
}
else{
return ctx.CurrentItem.CurrentRiskImpactLikelihood;
}
}
This works fine on page 1 of the values I return, it doesn't matter what the item limit of the pages in the view are, as soon as I go to the next page I get the following error:
TypeError: Cannot read property 'CurrentRiskImpactLikelihood' of null
Does anyone have any ideas on a fix for this? I've tried googling it but had no luck so far!
OnPostRender
? It seems to me that when it gets called on post-render, it would throw that error becausectx.CurrentItem
would not exist in the post-render phase. – Dylan Cristy Feb 22 '19 at 15:26