One of the more popular articles I’ve written in this blog is “Group By on more than 2 columns in a view”. As it has been over a year now, I decided to update the article and clean it up a bit. One of the problems many people had with it was not my solution, but how SharePoint handled the clicks on the Expand and Collapse buttons in the web part. When you clicked Expand at the top level it also expanded all the detail levels.
As background, SharePoint Views support grouping, but to only two levels. My article shows how to convert a View into a DataView web part and how to add as many levels of grouping you want. Many people thought that was cool, but complained that clicking the expand button expanded way too much.
After converting to a DataView and grouping (and adding a bit of color), the list looks like this:
Clicking on the second item expanded all of the detail below it, which made drill down painful.
I started with part of the ExpGroupBy code and added my own code to hand one level at a time expansion.
The DataView still starts out like this:
But now it expands only one level at a time:
And you can then drill down and only expose what you need!
Like all of my tricks (hacks?), you are on your own on this… and the safest place for this kind of code is in a Content Editor Web Part.
Note: Only tested with SharePoint 2007 and Internet Explorer (so far).
(If you have problems with Copy and Paste, copy and then paste in to Notepad, then copy and paste from there.)