1

enter image description hereenter image description hereI have a column which should define in list if the issue is in status: -Not Started, Active, Completed.

I would like to ideally add some colour to this by the row for example if completed it is green or active it is red. Then it highlights the whole row, do you know if this can be edited within the columns settings or if there any step by step instructions that can be followed to make this change? (ideally for someone new to sharepoint)

Thank You

fazsnatch
  • 15
  • 1
  • 4

1 Answers1

2

In SharePoint 2013 was introduced a so called Client Rendering Mode (CSR) which represents a rendering engine for list views, list forms and search results. I would recommend you to consider the following approach for your task.

Below example demonstrates how to highlight list task rows based on their status

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];
     }
    }
   }); 

});

How to apply the changes:

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

  1. Via JSLink property of web part.

  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: {Template JS code goes here}
  4. Save the page.

You can get more information about client side rendering, here.

Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61
  • I seem to have some limitations with this due to permission aspect. Is there anyway to do the colours via column formatting on JSON as per column? – fazsnatch Oct 24 '18 at 09:17
  • Also how do you add this to a list and not a page? – fazsnatch Oct 24 '18 at 09:31
  • go to your list, in All Items or anyother view-->Click gear(settings) icon on top right--> select Edit page --> Add web part(follow process given in answer). – Ganesh Sanap - MVP Oct 24 '18 at 09:48
  • If you want to color the whole row of item then follow the steps given in answer above. or if you want to create one more column to show the colored status based on Status column, that can also be possible....let me know about this. – Ganesh Sanap - MVP Oct 24 '18 at 09:50
  • Yes I tried this 'go to your list, in All Items or anyother view-->Click gear(settings) icon on top right--> select Edit page --> Add web part(follow process given in answer).' but seems like it is greyed out when I try to use it strangely. – fazsnatch Oct 24 '18 at 10:34
  • is it possible for you to attach screenshot of page(after you click on Edit page and showing Add Web Part section)?? – Ganesh Sanap - MVP Oct 24 '18 at 10:43
  • I have added it to above section – fazsnatch Oct 24 '18 at 11:02
  • Please see here how to add web part on page. – Ganesh Sanap - MVP Oct 24 '18 at 11:16
  • See 1st point in "Add a web part to a page" section, and look for this line "If neither the Page tab or the Edit command re there, click Settings button and then click Edit Page." – Ganesh Sanap - MVP Oct 24 '18 at 11:18
  • Thanks will give it a go. Will this then work for the list to see if that open is no longer greyed out? Reason is I am not using page but list. – fazsnatch Oct 24 '18 at 12:25
  • Yes, it will work on the list(apparently that is also a page in sharepoint). – Ganesh Sanap - MVP Oct 24 '18 at 12:28
  • Thanks Ganesh for your help. Just one more question, I have attached above the issue status. Do you know within links and columns if it the font colour for type of issue status can be changed. I.E - Active = Red Resolved = Green – fazsnatch Oct 24 '18 at 13:39
  • OOTB it is not possible(not on froms. in dropdown while selecting choice). to achieve this in similar way on list view, you need to write custom code in similar way with some enhancements. – Ganesh Sanap - MVP Oct 24 '18 at 13:43