There are different ways to color code the SharePoint list items however, in this example we will look at color coding the list items in a List View using CSR (Client-Side Rendering) or JS Link. For power end users, this is extremely helpful as it doesn’t require writing C# code or deploy any farm solutions etc.
Please read the Part 2 of the series for color coding the SharePoint list’s Display form.
We are going to use simple conditions to color code the list items.
- Green – If value is greater than 59
- Amber – if value is between 40 and 59
- Red – if value is between -100 and 39
End result will be:
In this example, we are using “Current Credit Score” field which is of “Single line of text” type.
- Create a Js file and add the following code in the file. Internal name of your field needs adding at line 6 and 15 instead of Current_x0020_Credit_x0020_Score.
- After making the changes to the above code, upload your updated file in the “Display Templates” folder of “Master Page Gallery” located at site collection level. Set the following properties of the file:
- Target Control Type: View
- Standalone: Override
- Target Scope: / (can be used anywhere in the site collection)
- Target List Template ID: 100 (for custom list) [List of all SharePoint list templates]
- Copy the URL of the uploaded JS file to clip board.
- Navigate to the list view and click “Edit Page” link on the settings cog. While page is in the edit mode, click on the “Edit Web Part” link of list view web part to view web part properties. Enter the URL of the JS file in the “JS Link” property of the web part under “Miscellaneous” category. Make sure the first part of URL has replaced with SharePoint URL token and the final URL should look similar to “~sitecollection/_catalogs/masterpage/Display Templates/ColorCodingListView.js”. Apply settings and Click OK to view the color coding applied to the list view.
Download the source code https://inteknix.com/download/16153/