Quickly filter a List/Document Library View using URL
Filed Under (Flash, JavaScript, SharePoint) by Boris Gomiunik on 27-02-2008
This one’s very useful when you’re having a lot of items in a list or document library and you need a quick filter.
If you’ll select the filter field it can happen that it will load for a long time. So lately I’m using URL. Suppose you have a long list of contacts and you need to find a contact named Boris.
In the AllItems.aspx – view of the page, add parameters
?FilterField1=[Field Name]&FilterValue1=[Value]
You can add more filterfield and filtervalue parameters to apply filters to more fields (FilterField2, FilterValue2, …)
The only trick is to know the Field Name like it’s saved in SharePoint. You can see this in the list settings page (click on a column name and check URL) or just make a manual filter for the first time.
In my case to find a contact with First Name Boris, I’d go to
http://[site_URL]/lists/contacts/AllItems.aspx?FilterField1=FirstName&FilterValue1=Boris
I’m always browsing a document library with filtering by specific document type. So I’ve created a simple script. Just add a Content Editor Webpart to your homepage, edit its source and add the following code (just update the url to your document library (docLibUrl):
<script type="text/javascript">
function docLib(dropdown) {
var vtype = dropdown.options[dropdown.selectedIndex].value;
var docLibUrl = "/Shared Documents/Forms/AllItems.aspx";
var filterField = "DocIcon"
if (vtype != ‘Select’) {
document.location=docLibUrl+"?FilterField1="+filterField+"&FilterValue1="+vtype;
}
}
</script>
<select style="margin:10px; 0px;" id="DocumentTypes" onchange="docLib(this)">
<option value="Select">Select document type</option>
<option value="Select">– Office 2007 –</option>
<option value="docx">Word 2007</option>
<option value="xlsx">Excel 2007</option>
<option value="pptx">PowerPoint 2007</option>
<option value="Select">– Office 2003 –</option>
<option value="doc">Word 2003</option>
<option value="xls">Excel 2003</option>
<option value="ppt">PowerPoint 2003</option>
<option value="Select">– Other –</option>
<option value="pdf">Acrobat (PDF)</option>
</select>



This tip encapsulates everything that is great about SharePoint – a platform that provides the opportunity to implement extremely effective solutions simply!
And in sharing this great tip you have epitomised how fantastic the SharePoint community is, thanks.
I can only get this to work if both the field name and the value are a single text string (just as in your example).
What do you do if the field is
Full Name
and the value is
Boris Spassky
?
For FilterField1 you can freely enter spaces, since these will be converted to %20. So for Boris Spassky it will get translated to Boris%20Spassky.
Other story is the space in the FieldName. SharePoint translates spaces in field names to _x0020_.
Underscore (_) gets translated in the URL to %5F so in your case the filter field would be First%5Fx0020%5FName. But this can complicate your life. Just sort by First Name and check url. You’ll find the value in the SortField=… parameter. To finalize the story: In your case the parameters would be:
?FilterField1=Full%5fx0020%5fName&FilterValue1=Boris%20Spassky
There is an exception: If you’re doing this in SharePoint’s built-in list the “SharePoint” column name for Full Name is FullName, the parameters would start FilterField1=FullName. I could go on for quite some time about “SharePoint” column names, but that’s a topic for another post. Like mentioned before – to get the proper FilterField1 value just sort the view (click the column name in allitems.aspx) and watch the SortField parameter value.
Thanks Boris. It was I think the fact that the value accepts %20 but the Field Name doesn’t that got me.
Mike
If I wasn’t heterosexual I’d be kissing you right now.
This was exactly the thing I was looking for
I need a solution to filter one attribute (say ID) not exactly with one value but to two different values. Creating a view is simple, but how to write this in the url?
Chris
I’m not sure if this is possible, since it’s also not possible to do this through GUI dropdowns.
could you tell me if i want to create filter through url but not for exactly value, like filter for Date. i want to get the documents which the end Date < someDate. i have tried use the "greater than" but it is useless. thank you
is it possible to expand groups when the list has groupings set up?
using the url like ?FilterField1=Customer&FilterValue1=Walmart&Expand=true
This is great but I need to be able to filter more than one column.
How do I adapt the code so that I can have 3 drop downs? Then use a button to fire the script which reads the values from each drop down and then sends the URL to filter correctly?
Also on refresh of page after filtering would be great if drop downs displayed the value which the filters are set too.
Hi, Matt.
Multiple filters can be applied by using additional filter URL parameters (FilterField2, FilterValue2,…). I agree that the dropdown should show the selected filter value, but the example above was just a quick demo of how to make the URL Filter.
I believe the best way is to construct those 3 dropdowns using JavaScript so you can dynamically configure them and set the selected value.
hi,
i need to filter the view with more than one value for one of the fields(instead of using AND i want to use OR operator).
is this possible?
thank’s
Unfortunately not. As you can probably see through UI, multiple filters are available only for 1 value per column and using the AND operator for multiple columns.