On my list of awesome SharePoint ideas that I want to try and do, was giving users the ability to filter a page based on selected metadata. I decided to hurry up and do it thanks to a question on MSDN forums. Special thanks to Stefan Bauer for the starting of some great code!
I’ve created a CodePlex project which contains the code file, check it out at SharePoint Filter Page by Metadata. Very simply, users can click from a list of terms within a term set, and filter all web parts on the page.
- Metadata service application is running, and has a term set.
- Use a managed metadata site column (created in the root web) in each list/library containing the term set.
- All web parts on the page this is installed in has to use the same site column.
To use this script:
- Download FilterPagebyMetadata.txt from CodePlex.
- If your SharePoint site doesn’t have them already, download SPServices and jQuery and upload to SharePoint. I use the Site Assets folder in the root web, but you can pick anywhere you want.
- Open the FilterPagebyMetadata.txt in NotePad.
- Update lines 13 and 14 to point to your files from above.
- Update line 17 to your managed metadata site column name.
- Save the file.
- Upload to your SharePoint site. Again, I prefer to use the Site Assets folder in the root site.
- Browse to your page where you want to use the code.
- Insert a new Content Editor Web Part.
- Edit the web part and specify the Content Link value as the path to the FilterPagebyMetadata.txt file, i.e. /SiteAssets/FilterPagebyMetadata.txt.
- Click OK and save the page.
TADA! You’ll see the list of values from the metadata service, and when clicked, it’ll filter your page!
NOTE There is currently one issue however, and I’m not sure if we can get around it. If you include a web part to a list that does not have the same site column in it, that web part will error when filtering the page.