The following works in SP 2007, SP 2010 and Office 365/SharePoint Online
Microsoft has generally done a good job of keeping new versions of SharePoint compatible with the older versions. While over time some features have dropped out of the documentation, most still work. An example is the Query String option to sort and filter a list. This was a feature from “SharePoint Team Services”, which is what they called SharePoint “back when”! The Query String feature we will look at here is still documented in an officially “archived” document on TechNet named “Using the URL to sort or filter a list” that can be found here: http://technet.microsoft.com/library/cc751316.aspx As is often the case, I ran across the article by accident while searching for something else.
What’s a Query String?
A query string is a collection of more or more parameters added to the end of a URL. You see these throughout SharePoint and at most interactive web sites. As an example do a search using Bing.com for “techtrainingnotes”. After you click the search button your search text is appended to the URL and will look something like this: http://www.bing.com/search?q=techtrainingnotes. The first parameter in a query string is identified with a question mark and each additional parameter is identified with and ampersand. Here the parameter name is “q” and the value is “techtrainingnotes”.
For the filter and sort tricks we will create a URL that looks something list this:
The first part, “http://intranet/sites/training/Lists/Tasks/AllItems.aspx” is the path to a view of a list and everything from the question mark to the end is the query string.
Filtering One or More Columns
To filter a task list to show just “In Progress” tasks you would first visit a view that included the Status column. The URL to this list would look something like this:
To filter this view you would add two query string parameters to the URL that specify the column to filter on and the value to filter for. This URL might look like this:
You filter on more than column by adding additional FilterFieldX and FilterValueX parameters to the URL. To find all of Luis Bonifaz’s In Progress tasks you might use this query string:
?FilterField1=AssignedTo&FilterValue1=Luis Bonifaz&FilterField2=Status&FilterValue2=Not Started
Why “AssignedTo” and not “Assigned To”? List columns can have an internal name and a display name. You will always need to use the internal name in these queries. See “Finding the Real Column Name” at the end of this article to see how to find these internal names.
- There can be multiple filters per query named FilterField1, FilterField2, FilterField3, …, FilterFieldxxx
- FilterNameX is the column we are searching in – this column must be displayed in the page… i.e. it must be in the current view.
- FilterNameX is case sensitive! A misspelled or miscapitalized FilterNameX column name causes the filter to be ignored and returns all rows from the list… So “Title” works and “title” does not.
- FitlerNameX must be the internal name, which is not always the display name (details on how to find this name is at the end of this article)
- FilterValueX is not case sensitive – searches for “in progress” and “In Progress” return the same results
- FilterValueX does not support wild cards
- All of the filters are AND’d together – i.e. the row in the list must match all of the filters to be displayed
Filtering a Single Column with Multiple Values and Wild Cards
The FilterField/FilterValue parameters can only find exact matches and only on a single value per column. You can also use “FilterName=” and “FilterMultiValue=” parameters to filter a column on more than one item or with wild cards. If you want to display all “In Progress” and all “Completed” tasks you could use this query string:
You can also use wildcards in FilterMultiValue parameter:
You can combine FilterField/FilterValue with FilterName/FilterMultiValue when needed. Here’s an example to find all of Luis’s tasks with “meeting” in the task title:
- FilterName is the column we are searching in – this column must be displayed in the page… i.e. it must be in the current view.
- FilterName is case sensitive! A misspelled or miscapitalized FilterName causes the filter to be ignored and returns all rows from the list… So “Title” works and “title” does not
- FitlerName must be the internal name, which is not always the display name (details on how to find this name is at the end of this article)
- FilterMultiValue is not case sensitive – search for “in progress” and “In Progress” return the same results
- FilterMultiValue supports wild cards! – Searching for “task*” finds “Task 1”, “Task 2” etc
- As FilterMultValue contains the word “Multi” then you would expect to be able to filter on multiple terms… and you can – separate each term with a semicolon (;) like this: &FilterMultiValue=In Progress;Not Started
Be careful not to add any extra spaces. The following will not find “Not Started” because of the extra space after the semicolon: &FilterMultiValue=In Progress; Not Started
You can sort too!
You can use the SortField/SortDir to sort on any column in the view:
Sort can also be used with the other filters:
Filtering from Quick Launch and other Links
So how do you use this little tidbit of information? You can generally do what these filters do with a view. Views do have one have annoying limitation… you can only display the first 50 views created. Technically you can create more than 50, but only the first 50 get displayed. Besides, it’s kind of tedious creating all of those views.
Let’s say you have a list with your 350 retail stores and you wanted to be able to quickly display a view of the stores filtered by any one state. You could create the 50+ views (50 states plus the other postal codes), or you could:
- Add links in Quick Launch to selected states:
- Create a links list with all of the state codes and display it as a web part
- Create a links list with all of the state codes, but display it as a dropdown list (http://techtrainingnotes.blogspot.com/2010/12/sharepoint-convert-links-list-to.html)
Finding the Real Column Name!
The column name used as the FilterName parameter must be the internal name used by SharePoint, not the displayed name. As an example, in a task list there is a column named “% Complete”. The internal name of this column is “PercentComplete”. To find this name:
- Display the list
- Click the List (or Library) tab in the ribbon and click List (or Library) Settings
- Scroll to the bottom or the page and click the column name
- Explore the URL to find the internal name