I have a list where I use "Shaded" View Settings > Style". It makes the rows dynamically alternately colored by row.

However, when I apply the JSLink below to change the row color according to Status, the Shaded alternate row coloring disappears leaving only rows with status to have a row color. How can I keep the default shaded alternate row colors to remain but have the affected rows change color according to the JSlink?

(function() {  
var overrideCurrentContext = {};  
overrideCurrentContext.Templates = {};  
overrideCurrentContext.OnPostRender = HighlightProductRows;  
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);  })();

function HighlightProductRows(ctx) {  
var statusColors = {  
    'Decline': '#FFF1AD',  
    'Reaching Target': '#FFD800',  
    'Approved': '#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];      }  }  

OK been up looking for the answer hope it helps someone else. SO to make it so that the rows change according to the JSLink but keep the row colors alternating otherwise instead of using Style> Shaded in the view add a Content Editor WebPart then add a URL in "Content Link" pointing to a css that you have the following code.

<style>.ms-alternating{background-color: #F2F1EC;}</style>

Use what other color you prefer.

  • Thank You @Mike! This is the answer – Gennady G Nov 13 at 16:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.