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.


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.


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


(default view)

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

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”>
<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>

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!!!! Tags: ,,