Trying to color rows based off of the value of the "Status" column

However I cannot get it working as it keeps giving the following errors:

TypeError: Cannot read property 'style' of null

TypeError: Cannot read property 'style' of nullTypeError: Cannot read property '_events' of null

Debugging it, it seems to be failing on: var row = document.getElementById(rowId); and always coming up null.

Any ideas why it wouldn't be able to execute the getElementByID? This seems to be occuring whether I add it as a JSLink, or put it in a script or content editor... always the same error.


SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

 OnPostRender: function(ctx) {

   var statusColors =  {
      'Pending Investigation' : '#FFF1AD',  
      'Under Investigation' : '#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];

  • Can you post any of the source HTML? There needs to be a table row element <tr> on the page with an id attribute, that matches the value of rowId your passing...
    – WhiteHat
    Jul 31, 2015 at 17:52

1 Answer 1


so? What is rowId? And does it exist on the page. Your code looks fine at first sight.

BTW You can achieve the same effect without CSR and JSlink connection in a Calculated Columnn set to datatype=Number with Formula:

&"<img src=""/_layouts/images/blank.gif"" onload=""{"
  &"var row=this;while(row.tagName!='TR'){row=row.parentNode}"
  &IF([Status]="Pending Investigation","FFF1AD",IF([Status]="Completed","01DF3A","FFD800"))

Just works everywhere you display this Column. pros and cons versus CSR/JSlink at http://www.viewmaster365.com/#/How

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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