Wednesday, May 2, 2012

Change list items background color using sharepoint


Go to list allitems.aspx page,next go to design code.
Next go to </script> tag ..After that add the below code



<script type="text/javascript" language="javascript">
  var x = document.getElementsByTagName("TD") // find all of the TDs
  var i=0;
  for (i=0;i<x.length;i++)
  {

    if (x[i].className=="ms-vb2") //find the TDs styled for lists
    {

      if (x[i].innerHTML=="sreenu") //find the data to use to determine the color
      {
        x[i].parentNode.style.backgroundColor='red'; // set the color
      }

    //repeat the above for each data value

      if (x[i].innerHTML=="sharepoint developer")
      {
        x[i].parentNode.style.backgroundColor='lightgreen'; // set the color
      }

      if (x[i].innerHTML=="Completed")
      {
        x[i].parentNode.style.backgroundColor='lightblue'; // set the color
      }

      if (x[i].innerHTML=="Deferred")
      {
        x[i].parentNode.style.backgroundColor='lightgrey'; // set the color
      }

      if (x[i].innerHTML=="Waiting on someone else")
      {
        x[i].parentNode.style.backgroundColor='orange'; // set the color
      }

    }

  }
</script>

No comments:

Post a Comment