Hello,
I'm attempting to write a JS function that would color-code my list rows depending on who they're assigned to (IE. Superintendent, training manager, ect.), but I've ran into some issues trying to convert existing code into what I want.
I'd assume this is due to my lack of experience in javascript.
The code I've gotten so far is
(function () {
// Create object that have the context information about the field that we want to change it's output render
var priorityFiledContext = {};
priorityFiledContext.Templates = {};
priorityFiledContext.Templates.Fields = {
// Apply the new rendering for Priority field on List View
"Priority": { "View": priorityFiledTemplate }
};
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(priorityFiledContext);
})();
// This function provides the rendering logic for list view
function priorityFiledTemplate(ctx) {
var priority = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
// Return html element with appropriate color based on priority value
switch (priority) {
case "Superintendent":
return "<span style='color :#f00'>" + assigned + "</span>";
break;
case "Training Manager":
return "<span style='color :#ff6a00'>" + assigned + "</span>";
break;
case "Unassigned":
return "<span style='color :#cab023'>" + assigned + "</span>";
}
}But I'm honestly not really sure where to start.
How do I go about defining everything I need to.