Client Side Rendering was introduced in SharePoint 2013 and available in  SharePoint 2016 as well as SharePoint Online. The primary purpose of CSR is to  provide conditional formatting of data present within the List Views. Prior to  SharePoint 2013 XSLT formatting was the way to go in order to implement  conditional formatting of List Views. XSLT formatting required in depth  knowledge of working with XSL and debugging was also cumbersome. However with  CSR we can tap in to the rendering process and override some of the default  properties of the list view using JavaScript. Some of the properties that can be  overridden are. 
- OnPreRender
- OnPostRender
- View
- Body
- Item
- Fields
- Header
- Footer
OnPrerender allows us to write some logic even before the list view is  rendered while OnPostrender allows us to modify the list view once the view has  been rendered. Header, Footer and Body properties can be overridden to replace  the default header, footer and body behavior. Item property can be over ridden  to change the view of each of the list item during run time. Fields property can  be overridden to modify the column values during run time. 
 
 In this article we will be using client side rendering to highlight the  SharePoint list rows based on a particular condition. We will be over riding the  OnPostrender property using CSR and will highlight the rows if the column value  matches the condition. Ultimately we will have the list highlighted as below.
![]()
 
 JS Link Implementation
 
 The main entry point of Client Side Rendering is  SPClientTemplates.TemplateManager.RegisterTemplateOverrides. Prior to calling  this function, we will define which property we will be overriding as part  of the rendering process. Here we will be overriding the OnPostrender property.  HighlightProductRows is the function that will do the condition checking and  performs the run time rendering modification.
- (function()  
-  {  
-     var overrideCurrentContext = {};  
-     overrideCurrentContext.Templates = {};  
-     overrideCurrentContext.OnPostRender = HighlightProductRows;  
-     SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);  
- })();  
 
ctx.ListData.Row will get all the List rows which can be looped using a for  loop construct. For each item we will get the Status Column value and based on  the value we will set the back ground color as defined in the statusColors  array.
- function HighlightProductRows(ctx)   
- {  
-     var statusColors = {  
-         'Long way to target !': '#FFF1AD',  
-         'Reaching Target': '#FFD800',  
-         'On Target': '#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];  
-     }  
- }  
 
Add JS Link to List View
 
 Let’s see how to add the code as JSLink to the list view. Save the below code as  a JS file and upload it to one of the Libraries, say: Site Assets. 
 
 Full Code
 
- (function() {  
-     var overrideCurrentContext = {};  
-     overrideCurrentContext.Templates = {};  
-     overrideCurrentContext.OnPostRender = HighlightProductRows;  
-     SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);  
- })();  
-   
-   
- function HighlightProductRows(ctx) {  
-     var statusColors = {  
-         'Long way to target !': '#FFF1AD',  
-         'Reaching Target': '#FFD800',  
-         'On Target': '#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];  
-     }  
- }  
 
Go to the edit page of the list view by appending the URL “? ToolpaneView=2” at  the end of the list view’s .ASPX URL.
![]()
 
 Click Edit Web part for the list view. Under Miscellaneous section, there is a  text box to enter JSLink. Add the relative URL of the JS file after ~site or ~  sitecollection, depending upon the location of the Site Assets Library (or any  other repository), where you have uploaded the JS file. 
 
 ![]()
 
 Click Apply. This will apply JSLink to the SharePoint list view.
 
 Output
 
 ![]()
 
 Summary
 
 Thus, we have conditionally highlighted the rows of a list view in  SharePoint using Client Side Rendering and JSLink. This works the same way in  both SharePoint 2016 and SharePoint Online.