1,804 articles and 14,928 comments as of Monday, May 9th, 2011

EndUserSharePoint has combined resources with NothingButSharePoint.com. You can now find End User (Mark Miller), Developer (Jeremy Thake) and IT Pro SharePoint content all in one place!

This site is a historical archive and is no longer being updated. Please update your favorites, bookmarks and RSS feeds.

NothingButSharePoint.com
Thursday, September 2, 2010

SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP

Author: Jim Bob Howard

We’re in the home stretch… just a couple more tweaks to our DVWP to make it work a little better and then we’ll put all the pieces together.

Totally Awesome

To really make this worthwhile, we should do some grouping within our filtered views, along with some totals and sub-totals.

First, let’s turn on the grouping and see what we get OOTB.

  1. In SharePoint Designer (SPD), hover over your DVWP in the Design pane and click the chevron (right arrow), then click on Sort and Group

  2. Click Sort and Group near the top of Common Data View Tasks

  3. Choose the fields you want to use for grouping and/or sorting and click Add > >
  4. Anything you choose in the Available fields and Add > > to the Sort order will be sorted according to the Sort Properties.


    All choices are sorted…


    …but not all choices are grouped.

  5. For our purposes, we’re already filtering the DVWP by Location; grouping by it would be redundant. So we want to go down to the next level and group by Group. And we’ll sort by Worker name, per my requirements. It might instead make sense to sort by Position, depending on how the managers are most comfortable working with the data.

  6. Option 1: Showing column totals per group


    Option 2: Showing group footer

    It doesn’t really matter which option you choose because we’re going to be changing it in just a bit anyway. That said, I’ll be working from Option 2.

So, here’s our "before" and "after":


For the rest of this article, we’ll take care of the Group headers and footers (1-3).

Modifying Group Headers and Footers

The lowest-hanging fruit on this tree is (1) —the Group header. With only one grouping, it’s pretty redundant (and ugly) to indicate that this section is grouped in a Group, so let’s get rid of that text and just display the name of the Group.

  1. In SPD split view, click on any one of the Group headers in the Design pane to bring up the stylesheet in the Code pane.

  2. Click on the Group name in the Design pane to find the corresponding XSLT in the Code pane

  3. Delete the first four lines shown in the figure above.
  4.     <b>
            <xsl:value-of select="$fieldtitle" />
        </b>
        <xsl:if test="$fieldtitle">: </xsl:if>
    

    Delete this part

  5. Click in the Design pane

Subtotal Count

At first blush, it looks like we might not have to do anything to (2). And that’s true, if you like the way it looks. I want it to stand out a little more.

  1. In the SPD split view, click on any of the Group footers

  2. I like to have the subtotals a little darker and use the same background colors that are already in the grid. So, for every TD in this TR, I changed the class from ms-vh to ms-gb2 ms-alternating. I also prefer to have the label left-justified with the column title and data:
  3.     <td class="ms-gb2 ms-alternating" nowrap="">
            Count : <xsl:value-of select="count($nodeset)" /></td>
        <td class="ms-gb2 ms-alternating" nowrap="">
            <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
        </td>
        <td class="ms-gb2 ms-alternating" nowrap="">
            <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
    </td>
    
  4. Click in the Design for the reveal.

Adding a Subtotal Sum

On the same line with the count, I also need a calculation (3) of all the FTE hours for that Group.

  1. Click on the empty cell beneath the last row in the Group

  2. We’re going to put an FTE subtotal here…

  3. In the Code pane, this td tag will be highlighted. Replace…
  4.     <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
    

    …with…

        <xsl:value-of select="format-number(sum($nodeset/@FTE),'#0.00')"/>
    

    This will give us a sum() of all the @FTE amounts in this nodeset, which at this point are just the ones in this Group.

  5. To give it a meaningful title while keeping the subtotal lined up with the rest of the FTE amounts, we’ll need to put the title in the next cell to the left. Click it in Design to highlight it in Code.
  6. This time, we’ll replace…

        <xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text>
    

    …with…

        <nobr>Total <xsl:value-of select="$nodeset/@Group" />  FTE :</nobr>
    

    Here we’re just inserting the Group name for this nodeset.

  7. The only problem at this point is that putting the text in that td causes the smaller column of Work Shift to be artificially wide. So, let’s extend the subtitle into the previous td, too:
  8. Simply delete the preceding td and give this one a colspan of 2.

        <td class="ms-gb2 ms-alternating" nowrap="" colspan="2" align="right"></td>
    

    For aesthetic purposes, we’ve also right-aligned the td.

Page Totals

For the page totals (4 and 5), it would be great if those stood out a bit more, even if they’re just bigger. We’ll use the accounting style of a double line to show page totals.

  1. Click on the Count cell (4), as before.
  2. First, we’ll move the ms-alternating class to the tr so we don’t have to keep repeating it.
  3.     <tr valign="top" class="ms-alternating">
    </tr>
    
  4. We’ll remove the class attribute for all the td’s on this row. But, we’ll also add in a border-top to create the double-line accounting style:
  5.     <td nowrap="" style="border-top:medium black double">
    	</td>
    
  6. SharePoint adds an xsl:text tag to put a space before the Count title. I didn’t like it, so I removed it. In the rest of the TD’s—if they’re empty ones, the space is required to make the border-top appear.
  7. This time, our sum() will come from $Rows, rather than $nodeset:
  8.     <xsl:value-of select="format-number(sum($Rows/@FTE),'#0.00')"/>
    
  9. The title will need to extend into the previous cell again. This time, it will be a total for the Location, rather than the Group:
  10.     <td style="border-top:medium black double" nowrap="" colspan="2" align="right"> Total <xsl:value-of select="$Rows/@LocDept" /> FTE :</td>
    

    Since we’re going to use this same DVWP template for all of our Locations, it’s probably easier to "look up" the name of the Location. If you’ve used abbreviations like I have, you may want to type out the long name of the Location for this DVWP, since there’s only one per webpart.

Almost there

It’s looking better already.


Next time: One last tweak we’ll do next time: Icons for the Form action links.

Author: Jim Bob Howard

Jim Bob Howard is a web designer / webmaster in the healthcare industry. He has been working with SharePoint since March 2009 and enjoys sharing what he has learned. He is a moderator and frequent contributor to Stump the Panel, and answers SharePoint questions on Twitter (@jbhoward) and via email ([email protected]).

View all entries in this series: Extending the DVWP»
Entries in this series:
  1. SharePoint: Extending the DVWP - Part 1: Layout Enhancement - Rearranging Columns - Default and Edit Templates
  2. SharePoint: Extending the DVWP - Part 2: Layout Enhancement - Rearranging Columns - Insert Template
  3. SharePoint: Extending the DVWP – Part 3: Getting it All on One Line - DVWP Function Action Links
  4. SharePoint: Extending the DVWP – Part 4: Turning DVWP Action Links into Buttons
  5. SharePoint: Extending the DVWP – Part 5: Doing Stuff Before Save on Submit - PreSaveAction()
  6. SharePoint: Extending the DVWP – Part 6: Examining the Form Action Links
  7. SharePoint: Extending the DVWP – Part 7: Creating a Form Action Workflow
  8. SharePoint: Extending the DVWP – Part 8: Creating a Form Action Workflow - The After Math
  9. SharePoint: Extending the DVWP – Part 9: Oops! Failed Setting Processor Stylesheet
  10. SharePoint: Extending the DVWP – Part 10: Passing Workflow Variables to a Form Action Workflow
  11. SharePoint: Extending the DVWP – Part 11: Getting More Form Fields to the Workflow
  12. SharePoint: Extending the DVWP – Part 12: Adding More Form Fields from the Data
  13. SharePoint: Extending the DVWP – Part 13: Putting PreSaveAction() to Work – Creating Variables
  14. SharePoint: Extending the DVWP – Part 14: Putting PreSaveAction() to Work with jQuery
  15. SharePoint: Extending the DVWP – Part 15: User-Managed Dropdowns with Site Columns
  16. SharePoint: Extending the DVWP – Part 16: User-Managed Dropdowns - Loading Data
  17. SharePoint: Extending the DVWP – Part 17: User-Managed Dropdowns – Creating a Relationship list
  18. SharePoint: Extending the DVWP – Part 18: User-Managed Dropdowns – Loading the Relationship list – Part 1
  19. SharePoint: Extending the DVWP – Part 19: User-Managed Dropdowns – Loading the Relationship list – Part 2
  20. SharePoint: Extending the DVWP – Part 20: Cascading Dropdowns - Applying the jQuery
  21. SharePoint: Extending the DVWP – Part 21: Cascading Dropdowns - Three-tier Cascade
  22. SharePoint: Extending the DVWP – Part 22: Creating Title Based on Other Fields with jQuery
  23. SharePoint: Extending the DVWP – Part 23: Creating Title Based on Other Fields with a Workflow
  24. SharePoint: Extending the DVWP – Part 24: A Note to Readers
  25. SharePoint: Extending the DVWP – Part 25: Using an Audit Trail by Creating List Items with SPServices
  26. SharePoint: Extending the DVWP – Part 26: Modifying the Edit Template
  27. SharePoint: Extending the DVWP – Part 27: Adding an Alternate Edit Template to a DVWP
  28. ExSharePoint: Extending the DVWP – Part 28: Massage the Remove Template
  29. SharePoint: Extending the DVWP – Part 29: Modifying Form Action Workflows on the remove Template
  30. SharePoint: Extending the DVWP – Part 30: Using EasyTabs with Filtered DVWPs to Make Data Manageable
  31. SharePoint: Extending the DVWP – Part 31: Filling in Default Data on the insert Template with jQuery
  32. SharePoint: Extending the DVWP – Part 32: Filling in Default Data on the insert Template with Multiple DVWPs
  33. SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP
  34. SharePoint: Extending the DVWP – Part 34: Using Icons for Form Action Links
  35. SharePoint: Extending the DVWP – Part 35: Putting it All Together
  36. SharePoint: Extending the DVWP – Bonus: Fixing the Insert Form Action When "No Matching Items"
  37. SharePoint: Extending the DVWP – Bonus: Creating a Title Based on Dropdowns with jQuery
 

Please Join the Discussion

10 Responses to “SharePoint: Extending the DVWP – Part 33: Modifying Total and Subtotal Row Layouts in DVWP”
  1. A lot of nice detail! Excellent post.

    Stacy
    SharePoint Developer

  2. Dean says:

    In the group header i need to reformat the heading when the user chooses to group by Date or Percent complete. Could you please tell us how we can reformat these values so that they look like they do in the grid, i.e, 3% and 12/10/2010, instead of the default 0.300000 and 12/10/2010 12:00:00.
    Thanks
    Dean

  3. Sarunas says:

    Hi

    thank you for great post!

    I got problem with “sum(”

    “format-number(count($nodeset/@Hours” gives count result,
    but “format-number(sum($nodeset/@Hours” returns empty value

    what might be the reason?

    /sarunas

    • Probably because @Hours isn’t a number that can summed well. Try putting your format-number() inside the sum() rather than outside.

      e.g. sum(format-number($nodeset/@Hours))

      Make sure that Hours actually looks like a number, meaning it can’t have commas in it if your Hours are over 1000. Alternately, it may be that your sum() is what is going over 1000 and are then having trouble being number-formatted.

      …does that help?

      Blessings,
      Jim Bob

  4. Dave Schafer says:

    I ran across this post in a google search…. you better believe I’ll be going back to part 1 of the post and reading all the way through. Thanks for this post and I’m looking forward to reading through the series.

    I’m having an issue with grouping In a multi-item view where I’ve grouped a task list (displayed in a data view web part) by priority. I have “show group header” checked and the group is expanded by default. I have no options checked in the advanced grouping options. The group header is repeating for each task so I might have a header for “Normal Priority” displayed 20 times if there are 20 tasks with a normal priority instead of them all being grouped under one “normal priority” header.

    Below this multi-view I have inserted a joined subview. I have added grouping to the subview as well (which displays) but I want the subview collapsed by default. Choosing this option seems to have no effect in the joined subview. The option works fine in the multi-item view. Any ideas?

Trackbacks

Check out what others are saying about this post...
  1. [...] to make it look even nicer, we’ll massage the way total and subtotal rows look and replace some of our form action links with [...]




Notify me of comments to this article:


Speak and you will be heard.

We check comments hourly.
If you want a pic to show with your comment, go get a gravatar!