Archive for August, 2010

08/24/10
Fahad Zia

Display total number of filtered list items using jQuery


There are several options to make this happen but I wanted a quick way to display total number of filtered items(By filtered I mean using CAML operators). I could think of the following ways:

1. Custom Web Part
2. SharePoint Designer
3. Using jQuery and SharePoint Web Services

I opted for 3 after I found out i could do this using only CEWP.
http://spservices.codeplex.com/

here is my code:

<script type="text/javascript" src="_layouts/Project/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="_layouts/Project/jquery.SPServices-0.5.6.min.js"></script>
<script language="javascript" type="text/javascript">
var $j=jQuery.noConflict();
$j(document).ready(function() {
  var total="";
  $j().SPServices({
    operation: "GetListItems",
    async: false,
    listName: "Workflow Tasks",
    CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
    CAMLQuery:"<Query><Where><And><Neq><FieldRef Name='PercentComplete' /><Value Type='Number'>1</Value></Neq><Contains><FieldRef Name='ProjectStatus' /><Value Type='Text'>In Engineering</Value></Contains></And></Where></Query>",
    completefunc: function (xData, Status) {
      total=$j(xData.responseXML).find("[nodeName=rs:data]").attr("ItemCount");  
      $j("#lblTotalEngineering").text("Total Open Items (In Engineering): " + total);
     }
  });
});
</script>
<ul id="lblTotalEngineering"/>