0

I am using SharePoint Online 2013 and have a list. I have a risk status that people can choose where its red or green or yellow, its a drop down choice.

Now I want to add color to it. I want it to be those colors or like a circle or a bullet point almost next to it. I did do a script and made the entire list a certain color but I just want it in 1 cell.

Can anyone help please?

1

This is quite well documented online. There are two methods, the first is to use calculated columns (which I'd not personally recommend).

The second would be to use the jslink in the webpart and create the custom code. There are quite a few sites with online tutorials

reference 1

reference 2

0

Put this below code in content editor webpart or in JS file and connect it with JSLink property to your webpart.

Here it is using priority field. You can use your desired field.

Code:

(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];
    var color = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];

    // Return html element with appropriate color based on priority value
    switch (priority) {
        case "(1) High":
            return "<span style='color :#f00; background-color:#f00;'>" + priority + "</span>";
            break;
        case "(2) Normal":
            return "<span style='color :#ff6a00; background-color:#f6a00;'>" + priority + "</span>";
            break;
        case "(3) Low":
            return "<span style='color :#cab023; background-color:#cab023;'>" + priority + "</span>";
    }
}

Hope this will help you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.