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.

A few bugs to watch out for.

The below haven’t been confirmed as bugs by Microsoft yet, but I think they are. I posted them to the forums and at the very least, they are some things to watch out for.

MS Forum Link

I’m been using the data view a lot lately and I’ve noticed some oddities.  I’m curious if anyone else has come across these issues.

1) Group Totals don’t work for fields of type user.  If you group by any user field, modified by, created by, or roll your own, and you turn on totals (check box in advanced grouping). You can find the reason if you dig into the generated xsl.  To get the totals, it tries to do a sum on the nodeset, where the nodeset is the current group’s records.  The nodeset is created via a select statement where we compare the current group header to the matching field in the current row.  However, people fields come back as formatted html, and within that html is an image with an ID that changes for each row. 

<img name=’imnmark’ title=” border=’0′ height=’12′ width=’12′ src=’/_layouts/images/blank.gif’ alt=’No presence information’ sip=’xxx’ id=’imn_19907,type=sip’/>

so the string compare in the select statement is always false.

2) If you have groupings two levels deep, you cannot set both groups to be collapsed by default.  It will let you set both groups be collapsed, but if you hit ok it won’t function that way and then open it again, one of them will then be set to expand by default initially.

3) Related to #2, if you expand an outermost group, any inner groups are also expanded.

 

MS Forum Link

I had a user bring this scenario to my attention.  I have been able to repeat the issue as well.

The problem is that in the month calendar view of an events list, when many items fall in the same week so that the 1 more or 2 more arrows show up, in this scenario, clicking the down arrows will not show the extra events.

The cause centers around having an event that spans multiple days, but that isn’t set as an ‘all day event’.  So one that goes from say monday at 11:00 AM to Wednesday at 11:00 AM.

The workaround is to make sure any multi day events are checked as all day events.

  

To repeat the issue:

  1. Create an events list
  2. To the same week, add 2 week long events (check the box to make them all day events)
  3. To that same week, add an event that spans monday & tuesday (make it an all day event)
  4. To the same week, add an event that spans thursday and friday (make it an all day event)
  5. Add an hour long event on Wednesday – you should see the ’1 more’ arrow link instead of the event.  All is good, if you click the arrow, the event is displayed.
  6. Now add an event that spans Tuesday 2:00 – Thursday 2:00. – On the calendar, this will look just like an all day event.  Now if you click the ’1 more’  arrow, nothing happens, and the event in step 5 is not shown.