Quickly filter a List/Document Library View using URL

February 27th, 2008 | Categories: Flash, JavaScript, SharePoint | Tags:

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>

Oznake ponudnika Technorati: ,
  1. Matt Taylor
    February 27th, 2008 at 23:14
    Reply | Quote | #1

    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.

  2. Mike
    February 28th, 2008 at 09:17
    Reply | Quote | #2

    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

    ?

  3. Boris Gomiunik
    February 28th, 2008 at 20:55
    Reply | Quote | #3

    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.

  4. Mike
    March 1st, 2008 at 17:45
    Reply | Quote | #4

    Thanks Boris. It was I think the fact that the value accepts %20 but the Field Name doesn’t that got me.

    Mike

  5. Casper
    April 24th, 2008 at 08:44
    Reply | Quote | #5

    If I wasn’t heterosexual I’d be kissing you right now.
    This was exactly the thing I was looking for

  6. Chris
    November 7th, 2008 at 13:19
    Reply | Quote | #6

    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

  7. Boris Gomiunik
    November 8th, 2008 at 00:28
    Reply | Quote | #7

    I’m not sure if this is possible, since it’s also not possible to do this through GUI dropdowns.

  8. February 13th, 2009 at 03:33
    Reply | Quote | #8

    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

  9. Rolf
    June 29th, 2009 at 16:09
    Reply | Quote | #9

    is it possible to expand groups when the list has groupings set up?

  10. Rolf
    June 29th, 2009 at 16:10

    using the url like ?FilterField1=Customer&FilterValue1=Walmart&Expand=true

  11. Matt
    January 5th, 2010 at 14:10

    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.

  12. Boris Gomiunik
    January 25th, 2010 at 11:26

    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.

  13. natalie
    March 7th, 2010 at 07:38

    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

  14. Boris Gomiunik
    March 8th, 2010 at 23:48

    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.

  15. Clem
    July 8th, 2010 at 16:46

    It would be nice if the selection could be populated from a task list (Via a dataview web part).

  16. Clem
    July 8th, 2010 at 17:46

    I added the call to the docLib to a dataview web part in Designer. Then i changed the .value property to .text and used this to filter the document library. This allowed me to use a task list to populate the dropdown select list dynamically from another SharePoint list. Worked like a champ!

  17. guy
    August 20th, 2010 at 13:31

    To Boris:

    You can easily create a multi-filter in the same way, by using FilterName in stead of FilterFiled:
    .. .aspx?FilterName=ID&FilterValue=Boris;Guy

    It will filter all lines in your list where ID = Boris OR Guy

    One minor point: it is an OR operator within the same column,
    and.. I could not find a way to combine this with another filter.

    So.. my problem is.. I need a combined filter:
    1. a multifilter on f.i. column department (FilterName)
    2. a single filter on column month (FilterValue)

    Anybody?

  18. guy
    August 20th, 2010 at 14:02

    Euhm.. to Boris.. solutions can be very simple..
    Create a new column (which you do not show, but for filtering purposes only).

    The formula of the calcutaed column:
    =Department&Month (as in my previous example)

    Now I can use FilterName and FilterMultiValue for filtering, based on this new column.
    (With some wildcards in it if you like..)

    Remark: this is a good solution if you dynamically compose your URL..
    (like I do, in an application that gets its parameters from an excel user-interface)

    Guy

  19. Boris Gomiunik
    August 22nd, 2010 at 22:02

    @guy: Have you tried using FilterField1=…&FilterValue1=…&FilterField2=…&FilterValue2=…

  20. guy
    August 26th, 2010 at 12:29

    @Boris: this does not give me te chance to combine a MULTI filter with a single filter.
    I need to filter on multiple departments and – above that – 1 subject.

    ==>
    filter all lines that are dept 21 OR dept 25 (FilterName=Dept&FilterMultivalue=21;25)
    AND that have subject “Ocoo” (FilterField1=Subject&FilterValue1=Ocoo)

    Only, you cannot combine FilterName with FilterField ..

    Guy