Question

I want to know is there out of box feature for SharePoint List to give the color. For Example -

I've one list column Completed and Pending. So here I want if status is Pending it should be Red or If Status is completed it should be Green. Is there any OOTB feature avilable in SharePoint.

Please advice

Was it helpful?

Solution

It depends on your definition of OOTB. JSLink is a feature available OOTB, but involves client-side scripting. If this falls within your realm of possibilities, here's a link explaining how to use JSLink.

What you need to do is:

  1. Create a JavaScript file and upload it to your master page gallery as a new JavaScript Display Template.
  2. Specify the Name, Title and Description.
  3. Set the Target Control Type to View and Standalone to Override.
  4. Set Target Scope to the url of the website this override applies to.
  5. Specify the template ID for your list under Target List Template ID. Here is a list of the template ID's, if you don't know them.
  6. Save and Publish the template.

Simply modify the list view web part where you want this effect, and enter the url to the file in the JSLink option (under Advanced, I believe).

The JavaScript file contents should be the following:

(function() {
    var statusFieldCtx = { };

    statusFieldCtx.Templates = { };
    statusFieldCtx.Templates.Fields = {
        Status: {
            View: StatusFieldViewTemplate
        }
    };

    SPClientTemplates.TemplateManager.RegisterTemplateOverrides(
        statusFieldCtx
    );
})();

function StatusFieldViewTemplate(ctx) {
    var _statusValue = ctx.CurrentItem.Status;    // Status is the field.  Replace with whatever field you have.
    if (_statusValue === 'Completed') {
        return "<span style='background-color: green;'>" + _statusValue + "</span>";
    }
    if (_statusValue == 'In Progress') {
        return "<span style='background-color: yellow;'>" + _statusValue + "</span>";
    }
    return "<span style='background-color: red;'>" + _statusValue + "</span>";
}

OTHER TIPS

Using OOTB tools: Create a new column of type Calculated and set the Formula as

="<span style='background-color: " & IF([Status]="Pending","red","green") & ";'>" & [Status] & "</span>"

"The data type returned from this formula is" select any other value than "Single line of text" to avoid HTML escaping.

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top