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.).