Saturday, November 1, 2008

MOSS - Group Items with Item Count

Many times you might have been asked to change the SharePoint Library views with new columns, calculated columns etc. This technique explains how you can group the items based on a column and provide the item count under that group in the header.


So essentially something like this:

+ Project: XYZ (15 items)
+ Project: ABC (25 Items)


Its pretty simple to achieve the grouping but a small trick to display the item counts.

First open your site in SharePoint Designer and go to the Page view (mostly in the /POages directory)
Then right click on the ListView and convert to DataView.
Go to DataView Properties-->Groupby-->Collapse header
Then in the name column enter the following:

<xsl:value-of select="$fieldvalue" > : <xsl:value-of select="count($nodeset[*[name()=$fieldname]=$fieldvalue or ($fieldtype!='isodatetime' and @*[name()=$fieldname]=$fieldvalue) or ($fieldtype='isodatetime' and ddwrt:GenDisplayName(string(@*[name()=$fieldname]))=$fieldvalue) or (not(*[name()=$fieldname] or @*[name()=$fieldname]) and $fieldvalue = ' ')]/@ID)" />


--------- BANG !!! There you go... as easy as it gets