SOLVED

SharePoint List color rows based upon date ranges relative to the Due Date

%3CLINGO-SUB%20id%3D%22lingo-sub-2038168%22%20slang%3D%22en-US%22%3ESharePoint%20List%20color%20rows%20based%20upon%20date%20ranges%20relative%20to%20the%20Due%20Date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2038168%22%20slang%3D%22en-US%22%3E%3CP%3EI%20would%20like%20to%20know%20how%20to%20color%20the%20rows%20on%20my%20SharePoint%20list.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20Due%20Date%20column%20in%20my%20list%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EHere%20is%20what%20I%20am%20looking%20to%20do%3A%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20Today's%20date%20is%20within%2014%20days%20of%20the%20Due%20Date%20then%20the%20entire%20row%20should%20be%20the%20color%20red%3C%2FP%3E%3CP%3EIf%20Today's%20date%20is%20between%2015%20days%20and%2021%20Days%20out%20from%20the%20Due%20Date%2C%20then%20the%20entire%20row%20color%20should%20be%20orange%3C%2FP%3E%3CP%3EIf%20Today's%20date%20is%20between%2021%20days%20and%2030%20days%20out%20from%20the%20Due%20Date%2C%20then%20the%20entire%20row%20should%20be%20yellow%3C%2FP%3E%3CP%3EIf%20Today's%20date%20is%2031%20days%20or%20more%20out%20from%20the%20Due%20Date%2C%20then%20the%20entire%20row%20should%20be%20Green%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20am%20assuming%20I%20will%20be%20using%20Client%20Side%20Rendering%20(I%20don't%20know%20I%20am%20guessing).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E1.%20What%20files%20will%20I%20need%20to%20create%20(a%20.txt%20file%20or%20a%20.txt%20file%20that%20is%20converted%20to%20a%20.js%20file%3F%3C%2FP%3E%3CP%3E2.%20Will%20I%20have%20to%20use%20Content%20Editor%20Web%20Part%20to%20refernece%20the%20.txt%20or%20.js%20file%3F%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2038168%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EColor%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Edue%20date%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Elist%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2038893%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20List%20color%20rows%20based%20upon%20date%20ranges%20relative%20to%20the%20Due%20Date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2038893%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F920389%22%20target%3D%22_blank%22%3E%40Joseph_Butler%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAre%20you%20using%20SharePoint%20Online%20and%20modern%20lists%20experience%3F%20For%20modern%20lists%20experience%20view%20formatting%20is%20done%20with%20JSON.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-2049812%22%20slang%3D%22en-US%22%3ERe%3A%20SharePoint%20List%20color%20rows%20based%20upon%20date%20ranges%20relative%20to%20the%20Due%20Date%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2049812%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F5628%22%20target%3D%22_blank%22%3E%40Matti%20Paukkonen%3C%2FA%3EI%20am%20not.%20We%20are%20using%20SharePoint%202013%20on-premise%3C%2FP%3E%3C%2FLINGO-BODY%3E
Occasional Contributor

I would like to know how to color the rows on my SharePoint list.

 

I have a Due Date column in my list

 

Here is what I am looking to do:

 

If Today's date is within 14 days of the Due Date then the entire row should be the color red

If Today's date is between 15 days and 21 Days out from the Due Date, then the entire row color should be orange

If Today's date is between 21 days and 30 days out from the Due Date, then the entire row should be yellow

If Today's date is 31 days or more out from the Due Date, then the entire row should be Green

 

I am assuming I will be using Client Side Rendering (I don't know I am guessing).

 

1. What files will I need to create (a .txt file or a .txt file that is converted to a .js file?

2. Will I have to use Content Editor Web Part to refernece the .txt or .js file?

7 Replies

@Joseph_Butler 

 

Are you using SharePoint Online and modern lists experience? For modern lists experience view formatting is done with JSON. 

@Joseph_Butler 

 

You can easily achieve this using SharePoint JSON View formatting

 

You need to use additionalRowClass to highlight the row based on conditions. Check my answers given at below links. It should help you to get started with it:

  1. Need Help with “Format View” feature in Modern List based on Condition 
  2. color formatting a date column - Refer the date conditions to check how you can use "@now" in JSON

Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

 

@Matti PaukkonenI am not. We are using SharePoint 2013 on-premise

best response confirmed by Joseph_Butler (Occasional Contributor)
Solution

@Joseph_Butler 

 

For SharePoint 2013, you can use Client Side Rendering (CSR) which represents a rendering engine for list views.

 

You can refer the code samples given in below links and modify it according to your conditions:

  1. How to highlight the row in red if expiration date is passed for SharePoint 2013 list 
  2. SharePoint 2013 on-prem conditional formatting row by dueDate 

Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.

 

@ganeshsanapIt appears the the code offered in the links provided allow me to color code items,

 

However, I am not finding the code needed in order to complete the "else if" regarding date ranges.

 

I have done extensive searches on Google and just not seeing the code needed. Any ideas?

@Joseph_Butler

 

for example:

 

For the following code, I get it...if the DueDate field for the row is less than Today, then the row will be red.

  else if (dueDate < now) {
        row.style.backgroundColor ='red'  ;
    }

 

What I would like to is set this to if the DueDate field for the row is 13 days out or less from Today, the the field should be red. When I make the changes below, it does not work.

  else if (dueDate <= now+13) {
        row.style.backgroundColor ='red'  ;
    }

 

Granted, I know nothing about scripting, other than guessing and I haven't found anything on Google that shows how to do this.



@Joseph_Butler 

 

In JavaScript, you can get current date & time using:

 

 

var currentDate = new Date();

 

 

To add the days to today's date using JavaScript, you can refer below link:

 

Add days to JavaScript Date 


Please click Mark as Best Response if my post helped you to solve your issue. This will help others to find the correct solution easily. It also closes the item. If the post was useful in other ways, please consider giving it Like.