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>
17 comments:
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
THanks for the post and it really inspires me...
but what bothers me is the query string does not work on my MOSS, no matter what queries i made are the same, they just return all items in the view...
btw, what if i want to filter those items partially match the keyword, aka 'like' in sql?
hey. this is a deadly article... I almsot have this project complete due to finding your article... But one thing I was to do, is it possible to add more fields and instead of doing an AND type query, do an OR. So it would be if field1=this or field2=this..
?FilterField1=PrimAppoint&FilterValue1=Classics&FilterField2=SecAppoint&FilterValue2=Classics
Above would be if both are equal, but what if one or the oither is equal? Any ideas? my email is swwalsh@swgc.mun.ca
/bump...
this is really good code. I'm applying this to my site now.
How can you filter a picture library on a keyword column thorugh a querystring?
Stoopid question but how can i get your code to work with a text box and submit button?
A quick answer would be:
1. add a content editor web part to page
2. add the following code:
------
<script type="text/javascript">
function filter() {
document.location='AllItems.aspx?FilterField1=Title&FilterValue1='+document.getElementById('filterBox').value
}
</script>
<input id="filterBox" type=text>
<button onclick="filter()">Filter</button>
----
Ofcourse modify the appropriate location if you're not adding the CEWP to the allitems.aspx page or modify the filter according to which field you wish to filter by.
Hope that helps
Does anyone have an example using multiple filters as described?
(filterField2, Filtervalue2)
Thanks
To use multiple, just add the parameter and value pairs separated by ampersand:
?FilterField1=[Field Name]&FilterValue1=[Value]&FilterField2=[second Field name]&FilterValue2=[second Field value]&FilterField3=[third field name]&FilterValue3=[third field value]...
In regards to Steve Walsh's question, instead of using ampersand wouldn't you use a pipe|symbol for the or operator?
I don't know if this will work i'm just throwing out ideas.
I'm not really a programmer :)
I guess I'm just not seeing it. When you want to filter by multiple fields do you use multiple drop downs?
I'll keep plugging away. Thanks for any help and examples.
Thank you.. It worked for me..
pipes instead of &'s.... well that breaks how URL's are formated.
I too need to find out how to do:
* OR instead of AND
* Contains instead of exact match
* NOT EQUAL
* ONE OF many values
* Greater thank
* Less than
The only thing I have figured out is that I need to have a calculated column that boils things down to an exact match... which is not optimal as I have 77 columns and each column can have up to 4 values... so I need 77 * 4 * 3 * 2 different calculated columns?
Post a Comment