Travis Lingenfelder
Travis is a Senior Lead Consultant for Catapult Systems and blogs about Microsoft technologies including SharePoint, but is passionate about all things relating to technology. Travis is a MCTS for SharePoint Server 2007 and 2010, application development and configuration.

Advanced Data View Web Part Sorting, Grouping, and Filtering   

Tags: Development, SharePoint, Web Parts
Technorati Tags: , ,

The data view Web Part I must say is probably my absolute favorite thing Microsoft included with SharePoint. It also has some really nice filtering capabilities built-in. Most of us are probably familiar with the Sort and Group dialog that is part of the Common Data View Tasks shown in the image below.

062508_2202_Filteringth1

What most people don't realize is that the Data View Web Part has a very nice toolbar that can be used in the browser that will allow the user to choose their own sorting and grouping. To enable this toolbar, select Change Layout … from the Common Data View Tasks menu and select Show toolbar with options for: on the General tab of the Data View Properties dialog.

 062508_2202_Filteringth2

This will give you a toolbar for the DVWP that looks like the following:


(default view)
062508_2202_Filteringth3

(filter expanded, showing a filter value for EVERY column in the dataset)
062508_2202_Filteringth4

 

The default behavior of the filter row in the toolbar is to show a filter drop down for every column in the dataset. While this gives the user complete control of what they want to filter, it can also make the width of the web part very big.

Now, this is where the fun comes in. I wanted to (1) have the filter view expanded by default (2) have a default view for sorting and grouping (3) only show a subset of the filter values.

The first two challenges are easy, in the source XSL for the DVWP look for a parameter called dvt_adhocmode and give it a value of filter.

    <xsl:param name="dvt_adhocmode">filter</xsl:param>

Setting the default sort and grouping options is also just as easy. Set the parameter values to the names of the columns in the data set for each corresponding parameter.

    <xsl:param name="dvt_groupfield">Practice</xsl:param>
    <xsl:param name="dvt_sortfield">ClientName</xsl:param>

So far so good. Now all that is left to do is to remove the filters that we do not want to show. To find the correct location in the XSL where this should be done, search for the following text:

<xsl:if test="$dvt_adhocmode = 'filter'" ddwrt:cf_ignore="1">

Just below this xsl:if statement, a table is created that contains the filter drop downs. To remove a filter delete everything in between and including the <th> and </th> tags for that element. For example, In the above filter row I want to remove the ProjectName filter, I would find the section that corresponds to the column that I don't want to show and where the filedname parameter matches ProjectName and I would delete the entire section shown below.

                    <th nowrap="nowrap">
                        <table>
                            <tr>
                                <td class="ms-toolbar" nowrap="nowrap">
                                    <xsl:call-template name="dvt.filterfield">
                                        <xsl:with-param name="fieldname">ProjectName</xsl:with-param>
                                        <xsl:with-param name="fieldtitle">ProjectName</xsl:with-param>
                                        <xsl:with-param name="Rows" select="$Rows" />
                                        <xsl:with-param name="fieldtype">text</xsl:with-param>
                                    </xsl:call-template>
                                </td>
                            </tr>
                        </table>
                    </th>

Once I have removed all of the filters that I don't want to show. The only thing left to do is to change each fieldtitle parameter to give a little bit more of a friendly name.

That's it!!!!

 

del.icio.us Tags: ,,
 
Posted by  Travis Lingenfelder  on  7/29/2009
14  Comments  |  Trackback Url  | 0  Links to this post | Bookmark this post with:        
 

Links to this post


Trackback from  David Broussard  on  8/20/2009  1:34 PM
A Guide to SharePoint Performance Testing (Part I) – What is “Acceptable” Anyway? 

[...] Recently I was involved in a couple of engagements to perfor ... [...]






Pingback from  [RESOLVED]Load and performance testing using .net 2008 | Asp Forum  on  9/10/2014  12:53 PM

Comments


Dan Hillman  commented on  Monday, September 21, 2009  12:27 PM 
nice post - helps me make the dvwp more useful. One question though, my dvwp uses an aggregate datasource that links two lists. One of my view columns is obtained from a joined subview. In the filters this column just shows up as "Row" with only (All) and (Empty) as selections. Any idea on how to enable a filter for such a column? thanks


mohsin  commented on  Monday, November 23, 2009  12:14 AM 
Hi, it is good article and helped me alot.

i want to ask that when i change the filter's default behavior as mentioned in the article by altering statement to "<xsl:param name="dvt_adhocmode">filter</xsl:param>", i get error msg in my SPD ("Sharepoint designer cannot render the XSLT in Data view. Try to undo.....") and i cannot see my DVWP. Although everthing is working fine when i browse the page in explorer. Am i missing something??

futhermore is there any easy way in which i can add fuctionlaity of "contains" in the few filter fields?

Thanks


Madhusudan  commented on  Wednesday, May 05, 2010  7:13 AM 
Hi Thanks for the great article. My question is if there are repeating values in the filter values or subset of filter values it displays in that fashion only. What i need to do if i want to display unique values or to make it non repeating values.


Madhusudan  commented on  Wednesday, May 05, 2010  7:42 AM 
Hi Thanks for the great article. My question is if there are repeating values in the filter values or subset of filter values it displays in that fashion only. What i need to do if i want to display unique values or to make it non repeating values.


Ray G  commented on  Thursday, June 24, 2010  1:58 PM 
The grouping and sorting doesn't seem to work at all. Any ideas? I have tried using stored procs, simple selects, and a view. No matter which way I try to create the report the sorting and grouping doesn't work


Kurup  commented on  Wednesday, September 08, 2010  2:57 AM 
<pre>
To Madhusudan :

• To remove these duplicates in the data view webpart filter option , do the following:
In SPD Find the code:
<xsl:for-each select="msxsl:node-set($dvt_Rows)/*[not(@*[name()=$dvt_FieldNameNoAtSign]=preceding-sibling::*[1]/@*[name()=$dvt_FieldNameNoAtSign])]/@*[name()=$dvt_FieldNameNoAtSign]">
Remove the [1], like this:
<xsl:for-each select="msxsl:node-set($dvt_Rows)/*[not(@*[name()=$dvt_FieldNameNoAtSign]=preceding-sibling::*/@*[name()=$dvt_FieldNameNoAtSign])]/@*[name()=$dvt_FieldNameNoAtSign]">
This should remove the duplicate entries.
</pre>


Rao  commented on  Wednesday, September 08, 2010  10:46 AM 
Good Article. Thank alot. I have one question. "Have the filter view expanded by default". Could plz tell me the process what should I change in my code. Because I found more than one results for "dvt_adhocmode". Plz suggest me regarding this.

Thanks,
Rao...


Rao  commented on  Wednesday, September 08, 2010  11:03 AM 
Thanks. I got it.

Thanks,
Rao...


uzn  commented on  Monday, July 18, 2011  3:01 PM 
Thanks a lot for this article. I was looking around for a week for changing the filter options. You article is a like a savior. Thanks again.


Jenend  commented on  Thursday, October 11, 2012  6:59 PM 
You are a saint for publishing this info! My question now for you is how to edit the width of the filtered drop down boxes.


Hussain  commented on  Friday, December 28, 2012  11:10 PM 
Hi Travis,

Is this possible to disable filtering by adding CEWP. thaks.


Aslam  commented on  Saturday, March 16, 2013  2:49 AM 
How to handle managed metadata in the filter dropdoen box.currently it shoes with teh SID;#value


RajeshKumar Pilla  commented on  Friday, September 13, 2013  7:22 AM 
How to view the complete toolbar after selecting a value?. Instead of clicking the Change filter to show the entire toolbar. Is there any way to show entire toolbar skipping the Change filter step??


Venki  commented on  Thursday, May 15, 2014  1:19 PM 
nice post, can i make the filter expandable by default..

Name *:
URL:
Email:
Comment:


CAPTCHA Image Validation