Adding URL Query to filter Web Parts
The point of this walk through is to explain how to create filters for web parts based on the page URL. Web parts to be filtered must be XSLT Data View Web parts. One of the fields that exist in the web parts corresponding list or library must contain data that matches the page name. If filtering multiple web parts on a page you must complete the following steps for each one. !!Note that some performance issues may arise if your filter has to process through thousands and thousands of records!!
- Add Web Part(s) to page
- Open page in SharePoint Designer
- Right Click on Web Part and Select Convert to XSLT Data View
- Select the Common Tasks
- To remove the tool bar select Change Layout
- Go to the General Tab
- Uncheck any boxes to remove the toolbar and filtering
- Click Ok
- Select Common Tasks
- Select Parameters…
- Enter New Parameter
- Enter CurrentUrl
- Select Server Variable as Parameter Source
- Enter URL as Server Variable
- Click Ok
- Select the Common Tasks
- Select Filter
- Check Add XSLT Filtering
- Click Edit
- Enter the following code and/or adapt it to your use[@Title=substring-after(substring-before($CurrentUrl,'.aspx'),'/Pages/')]
Code Explanation
@Title = the field that contains the content that matches your page name (i.e. ProductA is an item in the Title field and ProductA.aspx is the page)
$CurrentUrl = the parameter we just created
/Pages/ = the document library the pages reside in (if your pages reside in a document library named Products set this to /Products/)
The query pulls out the red information to use as the filter criteria http://sharepoint/pages/page2.aspx and matches it against the field chosen. - Click Ok
- Click Ok
- Save your page, you will notice at this time that your web parts return no results, the results will not show because the filter only processes at runtime.
- Refresh the page
Actual Code that is added to the Page is as follows:
In Parameter Bindingsparameterbinding location="ServerVariable(URL)" defaultvalue="" name="CurrentUrl"
In XSL Style Sheet
xsl:param name="CurrentUrl"
In xsl:template name="dvt_1"
xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[@Title=substring-after(substring-before($CurrentUrl,'.aspx'),'/Pages/')]"
No comments:
Post a Comment