Resolved: Grouping Issues in SharePoint Data View WebPart – Part1

SharePoint Data View WebPart grouping and Filtering:

Not always we can use the filtering conditions in a Data View WebPart, say for example we have few parameters (Group, SubGroup, level etc..) passed in Query String and based on these parameters we need to filter our Data View WebPart.
One of the Parameters (say SubGroup) may be sent as “All”, instead of selecting individual items. In this particular scenario we cannot use the default Filters available in Data View WebPart, hence we go for individual Row verification against these parameters. Till this point everything works fine and looks great. Lets now discuss about the problem:
Grouping Issue
If we set grouping to the results we see that the data is filtered properly according to our requirement but then , we can also all other Group Headers, which are does not meet the criteria (though there will not be any data available under these headers). Please refer the adjacent screenshot

Initial Fix
The first possible solution anyone can think of is to add the same filtering condition where the Group header (in XSLT) is being added and I did the same too and found that it resolved the issue to some extent. It would remove the main Group Headers but the second level grouping (if exists would still be there)Please refer below screenshot for the resultant Data after the modifications.

But applying the same filter to the next Grouping level wouldn’t work instead it would add additional issues, I would not go in to its details. So I opted to get it done with JavaScript:
Steps to be followed:
Find the Row where the actual data is being rendering by default in the dvt_1.rowview template.
For its TR add an ID attribute and assign its value to “displayRows”
Add the below script to you page:
function HideGroup()
var vTable = document.getElementById(‘tblRows’);
var vTRelement = vTable.getElementsByTagName(“TR”);
for(i=0;i < vTRelement.length;i++)
if(vTRelement[i].id == “group1”)
var vNextSibling = vTRelement[i].nextSibling;
if(vNextSibling != null)
if( != “displayRows”)
vTRelement[i].style.display = “none”;
vTRelement[i].style.display = “none”;


This would hide all the Second Level Groups which does not have data under its category*. Now this may look like the issue is resolved. Consider say under Main Group (Group1) we have three Sub Groups (SubGroup1, SubGroup2, SubGroup3). This Group1 may have data for SubGroup1, SubGroup3 but not for SubGroup2. In this case SubGroup2 would also be displayed with no data under its section based on the filtering Condition. With the above the SubGroup2 would be hidden and cannot be seen. Here comes one more issue, that is while using the expand collapse button the hidden TR that is “SubGroup2” would be visible again (Refer adjacent Image: “Before”).



Find the Expand Collapse Image for Group Header (that is the main Group) which contains an OnClick function: onclick=”javascript:ExpGroupBy(this);return false;” change this to onclick=”javascript:ExpGroupBy(this);HideGroup();return false;” and now we are all set to see the expected results(Refer adjacent Image: “Result”)

More on this in my Next Blog

*Note: Since its the Second level group its value is “group1” as rendered by the browser, change it to appropriate value wherever necessary (first level “group0”, third level “group2” etc…)
This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Resolved: Grouping Issues in SharePoint Data View WebPart – Part1

  1. Pingback: Resolved: Grouping Issues in SharePoint Data View WebPart – Part2 | SharePoint Tips and Tricks

  2. Niyaz says:


    Thanks for the post. I have followed as mentioned the steps in the blog but it didnot work for me. The HideGroup() not at all calling in to sharepoint.I kept it in CEWP. Could you please share this blog in details for us.


    • Venkat Karri says:

      Hi Niyaz,

      Have you followed all the steps mentioned in the blog? If yes, the only reason I see for Javascript function not firing is for the master page settings. Change “defer” attribute to “true” (refer my first blog for more details on this)


  3. Wow! Finally I got a web site from where I be capable of truly obtain useeful
    facts concerning my study and knowledge.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s