I have the following code. I'm trying to change row background colors based on the status field. But it is not working.

  OnPostRender: function(ctx) {
    var rows = ctx.ListData.Row;
    for (var i=0;i<rows.length;i++)
      var Completed = rows[i]["_ModerationStatus."] == "0";
      if (Completed)
        var rowElementId = GenerateIIDForListItem(ctx, rows[i]);
        var tr = document.getElementById(rowElementId);
        tr.style.backgroundColor = "#00ff00";
  • You might check this here: sharepoint.stackexchange.com/questions/132857/…
    – Patrick
    Apr 22 '16 at 6:24
  • i am trying this code but this is not giving me any result
    – user52650
    Apr 22 '16 at 6:24
  • That script is definitly working. Please try creating a new list with just title and status plus the status values and add the script into an script editor
    – Patrick
    Apr 22 '16 at 6:31
  • yeah but i need to run that code without using "for" or foreach
    – user52650
    Apr 22 '16 at 7:02
  • Put a debugger; statement before the Completed declaration and trace what happens Apr 22 '16 at 12:57

If you are putting this script in JSLink and it is not working then try putting this code in Script Editor WebPart because it worked for me.

If you are facing any other issue please let me know.


  • yeah its working
    – user52650
    Apr 25 '16 at 9:09

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.