I am currently trying to get color coding on a list to highlight good medium and bad properties.
I have tried to follow the examples shown here for color coding: SharePoint 2013 Client Side Rendering: List Views
As well as here: Color code item row based on column value in SharePoint Foundation 2013
I cannot figure out why none of the approaches are succeding for me. I have placed it as a webpart on the site and tested that i was able to modify the tables by just adding a footer text. But it must be something about reading the custom field.
The latest i used in the webpart was:
<script type="text/javascript">
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var statusColors = {
'BP Authorized' : '#FFF1AD',
'Other' : '#FFD800',
'BP Selected' : '#01DF3A'
};
var rows = ctx.ListData.Row;
for (var i=0;i<rows.length;i++)
{
var status = rows[i]["CATEGORY"];
var rowId = GenerateIIDForListItem(ctx, rows[i]);
var row = document.getElementById(rowId);
row.style.backgroundColor = statusColors[status];
}
}
});
</script>
CATEGORY
(exactly that, in all caps) is the internal name of the column? Also, what type of column is it? I created a test list, added a choice column with that exact internal name, with those exact choice values, and added your code as-is through a content editor web part below the LVWP (just as you describe), and your code works fine. The only things I can think of are if you don't have the column internal name right, or if it is a lookup or some other type of column and the column values are not the strings you are expecting.CATEOGRY
- It is as custom column with a typechoice
.