none
Color Code SharePoint List RRS feed

  • Question

  • hi

    how to color code a SharePoint 2013 list with Yes/No Condition

    if Cr=Yes it should be Red

    else it should be Blue

    there are  Group by and a total in the view


    Alen Austin


    • Edited by Alen Austin Monday, February 15, 2016 12:10 PM
    Monday, February 15, 2016 11:53 AM

Answers

  • Hi Alen,

    I have done a test in my SharePoint 2013.

    1.Create a list named test list, group by Title field and count Title field, it contains a Yes/No column named yes, color SharePoint list by yes field .

    2. Add a content edit web part in Allitems.aspx page and add the following code:

    <script type="text/javascript">
    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    
       SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
         OnPostRender: function(ctx) {
    
           var statusColors =  {
              'Yes' : '#FF0000',  
              'No' :  '#0000FF'
    
           };
    
           var rows = ctx.ListData.Row;
           for (var i=0;i<rows.length;i++)
           {
              var status = rows[i]["yes"];
              var rowId = GenerateIIDForListItem(ctx, rows[i]);
              var row = document.getElementById(rowId); 
              row.style.backgroundColor = statusColors[status];
           }
         }
       }); 
    
    });
    </script> 

    Then the test list looks like the following:

    If it still not working for you, please offer a screenshot about your list and which column you are used for group and count.

    Best Regards,

    Lisa Chen


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, February 16, 2016 6:08 AM
    Moderator

All replies

  • You can do it using SharePoint Designer or JSLink Web Part. Refer to the following post for more information

    http://sharepoint.stackexchange.com/questions/132857/color-code-item-row-based-on-column-value-in-sharepoint-foundation-2013


    Cheers,

    Visual Studio Developer Tools Download

    Monday, February 15, 2016 12:00 PM
  • Hi Alen

    This can be very easy using Calculated Columns .

    So 1) if you want to show like above image then you can simply add a calculated column like this 

    http://thinketg.com/creating-a-stoplight-color-coded-status-in-a-sharepoint-2013-list/

    2)If you want to highlight whole row based on Yes/No Condition then add a Script Editor to that page and add following script to it

    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];
           }
         }
       }); 
    
    });
    http://stackoverflow.com/questions/27317668/how-to-color-code-rows-in-a-sharepoint-list-for-each-page


    Amit Kotha

    Monday, February 15, 2016 12:19 PM
  • Dear Amit,

    there is grouping and total coming in the View so its not working.


    Alen Austin

    Monday, February 15, 2016 1:13 PM
  • Hi Alen,

    The best way would be to use a custom display template on the field. This can be applied to either the list view web part, or the view of a list and affects only the field rendering that it's configured for, regardless of grouping or filtering.

    Wes Preston has a great primer for all things Display Templates which you can view here:- Wes Prestons JS Link Primer

    The first example on that page covers field rendering, then you can replace the output with a block of HTML that includes colour coding for the specific field. If you want to colour code the row, then take a look at Wendy O'Neals stuff that she did for Collab 365 last year. http://wendy-neal.com/2015/10/enhance-the-usability-of-your-sharepoint-site-with-jslink-collab365-c365114/

    Paul.


    Please ensure that you mark a question as Answered once you receive a satisfactory response. This helps people in future when searching and helps prevent the same questions being asked multiple times.

    Monday, February 15, 2016 1:23 PM
  • No Prasanth still no change

    Alen Austin

    Monday, February 15, 2016 1:30 PM
  • Hi

    use sharepoint designer and format the webpart


    Romeo Donca, Orange Romania (MCSE, MCITP, CCNA) Please Mark As Answer if my post solves your problem or Vote As Helpful if the post has been helpful for you.

    Monday, February 15, 2016 2:14 PM
  • Hi Alen,

    I have done a test in my SharePoint 2013.

    1.Create a list named test list, group by Title field and count Title field, it contains a Yes/No column named yes, color SharePoint list by yes field .

    2. Add a content edit web part in Allitems.aspx page and add the following code:

    <script type="text/javascript">
    SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
    
       SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
         OnPostRender: function(ctx) {
    
           var statusColors =  {
              'Yes' : '#FF0000',  
              'No' :  '#0000FF'
    
           };
    
           var rows = ctx.ListData.Row;
           for (var i=0;i<rows.length;i++)
           {
              var status = rows[i]["yes"];
              var rowId = GenerateIIDForListItem(ctx, rows[i]);
              var row = document.getElementById(rowId); 
              row.style.backgroundColor = statusColors[status];
           }
         }
       }); 
    
    });
    </script> 

    Then the test list looks like the following:

    If it still not working for you, please offer a screenshot about your list and which column you are used for group and count.

    Best Regards,

    Lisa Chen


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Tuesday, February 16, 2016 6:08 AM
    Moderator
  • Dear Lisa,

    i did as you said please find the screen shot as there are 2 grouping and a total i have created the yes filed as you did and tried without changing the code uploaded it to the style library


    Alen Austin

    Tuesday, February 16, 2016 10:23 AM
  • Javascript is case sensitive. Lisa's example uses 'yes', whilst yours uses 'Yes'. For Javascript that may mean they aren't being pulled through.

    Try changing this line: 

      var status = rows[i]["yes"];

    to

      var status = rows[i]["Yes"];

    Tuesday, February 16, 2016 11:59 AM
  • Hi Alen,

    Yes, you can change the name of "Yes" column to "yes".

    Or you can change the code as: var status = rows[i]["Yes"];

    Feel free to reply back.

    Best Regards,

    Lisa Chen


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Thursday, February 18, 2016 2:16 AM
    Moderator
  • Dear Lisa,

    i did it let me recreate and try again.


    Alen Austin

    Thursday, February 18, 2016 6:14 AM
  • Hi Alen,

    Is there anything update?

    Please remember to mark the reply as an answer if it helps.

    Best regards,

    Lisa Chen


    TechNet Community Support
    Please remember to mark the replies as answers if they help, and unmark the answers if they provide no help. If you have feedback for TechNet Support, contact tnmff@microsoft.com.

    Monday, February 22, 2016 3:02 AM
    Moderator