Dynamic Filtering Based on List/Library Column


There might be a situation where you, as a site designer, have to create several views of a list or document library to show it’s contents filtered based on a column (eg: category) in it. Instead of creating so many views manually, you can use SharePoint Designer to create a Data View Web Part (DVWP) which dynamically filters the content based on the value of a column. The detailed procedure to created it is as follows.

Prerequisites:

  1. SharePoint site in which you are a design/owner.
  2. SharePoint Designer 2010 (installed in your workstation).
  3. Working knowledge in SharePoint Designer 2010.

Procedure:

The procedure includes two parts. First part is to create a page with a data view web part using SharePoint Designer to accept the column value as query string and filters the list based on that value. Second part is to create custom navigation links (in left navigation pane of the SharePoint site) to the same page containing the data view web part just by changing the query string value.

Part 1: Creating a page with Data View Web Part.

  1. Create a new page in the SharePoint site and save it (eg: DynamicView.aspx).
  2. Open SharePoint Designer (SPD) in your local workstation and open your site.
  3. Select ‘Site Pages’ (or the page library where you created the new page) on the left navigation pane and select the page you just created.
    001_PageLibrary
  4. Click on ‘Edit File > Edit File in Normal Mode’ in the ribon
    010_EditFileMenu
  5. After opening the page in design view (there is a tab on the bottom of the page to switch through Design, Code and Split views), place cursor within the main content placeholder and place a Data View Web Part (DVWP). In order to do this, expand Data View button in the ribbon under Insert tab and select the list/library you created in step 1.
    020_InsertDVWP
  6. Now, make sure that the newly placed data view web part is selected and click on Parameters button in the ribbon under Options tab.
  7. In the popup window, click on ‘New Parameter’ button to create a new parameter.
  8. Give a parameter name (eg: parDocCategory), select Query String as Source and give a name for Query String Variable. Click OK.
    030_NewParameter
  9. Again, make sure that the data view web part is selected and click on Filter button in the ribbon.
  10. Choose the list column you want to filter on (eg: DocCategory) as ‘Filter Name’ , Equals as Comparison and the parameter you created (eg: parDocCategory) as Value and click OK.
    040_NewFilter
  11. You are done creating a data view web part which is capable of filtering the list/library content based on the value passed to the page as query string. Part 1 is complete.

Part 2: Creating Links to Dynamic View Page.

In the example document library that this article refers to, I’ve created a Choice column called ‘Doc Category’ to filter the documents on. The values are Policies, Requests and Procedures. So I’ll have to create three navigation links on my SharePoint site to navigate to the same page I created in Part 1 but with different query string values (query String is a part of URL in the form "?QueryStringName=Value" used to pass data/values into a web page). For example, the URL for the page I created in Part 1 to list all documents in category ‘Policies’ should be https://<example_site_url>/SitePages/DynamicView.aspx?DocCategory=Policies.

In order to create the navigation links,

  1. In the SharePoint site, navigate to Site Settings > Navigation.
  2. Under Current Navigation, click on Add Link…
  3. Provide a Title (eg: Policy Documents) and URL as /SitePages/DynamicView.aspx?DocCategory=Policies">/SitePages/DynamicView.aspx?DocCategory=Policies">/SitePages/DynamicView.aspx?DocCategory=Policies">https://<your_site_url>/SitePages/DynamicView.aspx?DocCategory=Policies
    Note: The query string name ‘DocCategory’ has to be the same as one you provided for Query String Varable in step 8 of Part 1.
  4. Create links for other categories by just changing the query string value (eg: ?DocCategory=Requests, ?DocCategory=Procedures etc.).
Advertisements

4 thoughts on “Dynamic Filtering Based on List/Library Column

  1. Thank you finally, for a simple and concise explanation on how this works. Now, tell me, how can I apply the same dynamic filtering from the originating site to a list on another site?

  2. Unfortunately there is no option to select a list from another site while creating a list view web part. You may try creating the web part in the same site and then exporting and importing it into a different site using SharePoint designer. I believe it would ask you if you need to preserve association with the original list while exporting it. I haven’t tried it myself though.

    • Here’s my situation: I’m deveoping a site so that all of my clients can upload the documents I need to work on. I use qlistform to upload the docs to a document libary and then within qlistform, I use the dependent list feature to update a global log (list) on another site.

      the users also need to be able to 1) view their documents ONLY (I use key “client name”) in the document libary on the site, and 2) view their information ONLY on the global log on another site.

      I was able to accomplish #1 above using the dynamic filtering described in your article.

      For #2, I was thinking of using CAML advanced filters in the qlistform web part, but don’t know how to write the code.

      Any Suggestions?

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s