1

I have a list that I am using for a library check out. When a person populates the check out date field I want my row to be grayed out. The condition would be if a field contains "any" information. This will be a date field that will change when a person checks out book so it wont be static information. Do anyone know how to do this? Here is my script for doing this.

<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

   SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPostRender: function(ctx) {

       var statusColors =  { 
          "" : '#98FB98',
          "12/10/2019" : '#D3D3D3' 
       };

       var rows = ctx.ListData.Row;
       for (var i=0;i<rows.length;i++)
       {
          var status = rows[i]["Check_x0020_Out_x0020_Date"];
          var rowId = GenerateIIDForListItem(ctx, rows[i]);
          var row = document.getElementById(rowId); 
          row.style.backgroundColor = statusColors[status];
       }
     }
   }); 

});
</script>
2

Try changing your code to this:

<script type="text/javascript">
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {

   SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
     OnPostRender: function(ctx) {
       var rows = ctx.ListData.Row;
       for (var i=0;i<rows.length;i++)
       {
          var status = rows[i]["Check_x0020_Out_x0020_Date"];
          var rowId = GenerateIIDForListItem(ctx, rows[i]);
          var row = document.getElementById(rowId); 
          if (status)
          {
            row.style.backgroundColor = '#D3D3D3';
          }
          else
          {
            row.style.backgroundColor = '#98FB98';
          }          
       }
     }
   }); 
});
</script>
| improve this answer | |

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.