Tuesday, June 14, 2011

Highlight SharePoint List rows conditionally using jQuery !

In this article we will see how to Change the row Background color based on the value of a column in a sharepoint list and we will be doing it using jQuery.

Below is a screenshot of a Task Tracker whose rows are highlighted based on the percentage complete.

Here is how you can do it.

1. Create Sharepoint list

2. Edit allitems.aspx page and add a content editor web part and copy the below jQuery code to that webpart.

<script type="text/javascript">
$Text = $("td .ms-vb2:contains('Not Started')");
$Text.parent().css("background-color", "#461B7E");
var myelement = $Text.parent().parent();
$Text = $("td .ms-vb2:contains('Completed')");
$Text.parent().css("background-color", "#4CC417");
$Text = $("td .ms-vb2:contains('In Progress')");
$Text.parent().css("background-color", "#EAC117");

1 comment:

  1. Hi,

    Can this code be changed to higlight a row where the difference between the modified date and time and the current date and time is greater than two hours for example.