I am not a SharePoint guru and I don't know much about coding. I have a list which I would like to change the background color of the cell or row based on the Priorities ( (1) Critical, (2) High, (3) Medium, (4) Low).
Let's say Critical = red, High = orange, Medium = gold, Low = green.
I tried the use of calculated columns. (Which I have two right now) One of them is Color and the other one ColorBackground (). Not sure if I need two of them.
I guess the last step if some script to add the background color to the Priority column.
Can someone help??
I tried this using Content Editor wrap it as script. I changed the Share Point style to Basic Table and It didn't work.
SP.SOD.executeFunc("clienttemplates.js",
"SPClientTemplates", function() {
SPClientTemplates.TemplateManager.
RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var PriorityColors = {
'(1) Critical' : '#f08080',
'(2) High' : '#ffa07a',
'(3) Medium' : '#ffff00',
'(4) Low' : '#9acd32'
};
var rows = ctx.ListData.Row;
for (var i=0;i<rows.length;i++)
{
var Priority = rows[i]["Priority"];
var rowId = GenerateIIDForListItem(ctx, rows[i]);
var row = document.getElementById(rowId);
row.style.backgroundColor = PriorityColors[Priority];
}
}
});
});