2

I'm trying to setup a quick Highlight (i.e. conditional formatting) with SharePoint Designer 2013.

So if the item within the Field said "Red" then it would be highlighted Red. Having the text or just the background of the column is fine.

As I understand it SharePoint Designer 2010 had a pretty easy way to do this but I can't find out a way to do it in 2013?

Any help would be appreciated.

1

Or you could just create a calculated column with some HTML in it.

Create a calculated column and set it to be a number for the HTML to render correctly. You can set background color as highlighting or even different pictures as well.

HTML Calculated Column Example Uses - Color Coding

I just tried out the example from the link i provided, by creating a custom list with a choice column with Red, Green and Yellow as values. And then another calculated column with the following formula.

="<span style=""color:"&IF(Choices="","Black",IF(Choices="Red","Red",IF(Choices="Green","Green",IF(Choices="Yellow","Yellow","Black"))))&""">"&Choices&"</span>"

You can see the results below.

enter image description here

4

Conditional formatting the way it was available in SharePoint Designer 2010, not available in SharePoint Designer 2013 (Design view is removed from SharePoint Designer 2013).

In SharePoint 2013 was introduced a so called Client Rendering Mode (CSR) which is intended for rendering of List Views and Forms using HTML and JavaScript. I would recommend you to consider this approach.

To get acquainted with CSR follow these articles:

How to highlight the rows using CSR

Below example demonstrates how to customize List View in order to highlight tasks rows

Template code:

SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

   SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPostRender: function(ctx) {

       var statusColors =  {
          'Not Started' : '#FFF1AD',  
          'In Progress' : '#FFD800',
          'Completed' : '#01DF3A' 
       };

       var rows = ctx.ListData.Row;
       for (var i=0;i<rows.length;i++)
       {
          var status = rows[i]["Status"];
          var rowId = GenerateIIDForListItem(ctx, rows[i]);
          var row = document.getElementById(rowId); 
          row.style.backgroundColor = statusColors[status];
       }
     }
   }); 

});

Note: you have to specify the proper group name since in my case I am using group named Approvers

How to apply the changes

There are at least two options how to apply the changes:

  1. Using JSLink property
  2. Place JavaScript template on page via Script Editor/Content Editor web parts

Here is how to apply the changes using the second option:

  1. Switch the page into edit mode
  2. Add Script Editor webpart right below the list view web part.
  3. Put the specified code by wrapping it using script tag code into the Script Editor, for example: <script type="text/javascript">{Template JS code goes here}</script>
  4. Save the page

Results

enter image description here

  • 1
    Vadim, thank You much!) Works like a charm, and CSR method is very fast! p.s.: in my case column names contained spaces, so use static names like: var status = rows[i]["Communication_x0020_Status"]; – Gennady G Feb 16 '17 at 18:32
3

Try the step by step at this blog

It uses JSLink to customize the rendering of the fields

Here are more samples

Samples from MS

1

You can also color the whole row with some Javascript in that HTML calculated column. This example is based on the number in the Priority field so you'd have to rework it with the above IF statements to and replace that CHOOSE statement-line, to get the color right.

=[Priority]
&"<img src='/_layouts/images/blank.gif' onload=""
this.parentNode.parentNode.parentNode.style.backgroundColor='#"
&CHOOSE( RIGHT( LEFT( [Priority] , 2) , 1) , "fab" , "fda" , "9fa" )
&"';}"">"

Detailed explanation on how this works is at http://viewmaster365.com/#/How

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.