Intranoggin

Blither, Blather, Web Content Management.
Blog » Dataview Group Totals for People Fields

Dataview Group Totals for People Fields

I found a bug a little while ago in the SharePoint Designer created DataForm (dataview) web part. The bug stops you from creating group totals for groups based on people fields. Well, here's a workaround:

When you group by a people field, you'll get a template call for the header similar to this:

<xsl:call-template name="dvt_1.groupheader1">

    <xsl:with-param name="fieldtitle">UserFieldName</xsl:with-param>

    <xsl:with-param name="fieldname">UserFieldName</xsl:with-param>

    <xsl:with-param name="fieldvalue" select="$groupheader1" />

    <xsl:with-param name="fieldtype" select="'user'" />

    <xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((@UserFieldName)=$groupheader1 or ((not(@UserFieldName) or @UserFieldName='') and $groupheader1=' '))]" />

    <xsl:with-param name="groupid" select="'1'" />

    <xsl:with-param name="displaystyle" select="'none'" />

    <xsl:with-param name="imagesrc" select="'/_layouts/images/plus.gif'" />

    <xsl:with-param name="alttext" select="'expand'" />

    <xsl:with-param name="altname" select="'collapse'" />

    <xsl:with-param name="hidedetail" select="false()" />

    <xsl:with-param name="showheader" select="true()" />

    <xsl:with-param name="showheadercolumn" select="false()" />

</xsl:call-template>

Where @UserFieldName is the internal name for your people field.

To make the totals work, we need to make sure the nodeset variable is populated correctly, so replace this line:

<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[((@UserFieldName)=$groupheader1 or ((not(@UserFieldName) or @UserFieldName='') and $groupheader1=' '))]" />

with this line:

<xsl:with-param name="nodeset" select="msxsl:node-set($dvt_Rows)/root//Row[(((substring-before(substring-after(@UserFieldName,'HREF='),'&gt;'))=substring-before(substring-after($groupheader1,'HREF='),'&gt;'))or ((not(@UserFieldName) or @UserFieldName='') and $groupheader1=' '))]" />

The general idea here is that instead of comparing the whole value of the person field, we just pull out the value of the hyperlink that points to the user's details.

Now you can use aggregate functions like sum and count <xsl:value-of select="sum($nodeset/@Hours)" />

WARNING: after you make this change, it's unlikely that you'll be able to alter sorting or grouping again through the Designer UI.


Posted: 5/23/2008 8:24:00 AM by Ryan Miller | with 0 comments
Filed under: SharePoint