Tuesday, June 11, 2013

How to get the total record count in the customized xslt of a list view

The total of record count is sometimes useful when showing up on the list view. It’s a bit hard to get it directly from the list xml data (not sure whether it’s possible). The following is an easy approach.

First, you’ll need to modify you view to include the ID column. Then under the totals, set Count for the ID column in the dropdown.

image

image

Now save the view and open it in SharePoint designer, click Customize XSLT>Custom Entire View

image

Notice that in the xslt we have the following defined:

image

You can now define a global variable for the total count of records

image

This global variable can be used for customized pagination as well as just displaying the count of records on the page. After all this done, you can hide the id column by modify the xslt a bit.