Filtering ListViews with URL Query String

Saturday, December 08, 2012

18

They say that peering lightyears on lightyears out into space is like looking back in time.  Look far enough, and you can catch the very first moments of the universe.  SharePoint is also a universe of sorts.  It's certainly vast and complex enough, and random enough, too.  Its history is written in a maze of ever more obscure backward compatibility features, and the daring may peer into the gaping darkness.  Perhaps even reach in... and grope nifty things like filtering list views with URL parameters.

This technique isn't used much in SP 2010, but still works for backward compatibility.  You can sort and filter list views by tacking on some URL query string parameters.  It also works on any page with a ListView Webpart.

This post will cover:

  • Basic URL filters
  • Filtering multiple columns
  • Multiple filter values on a single column
  • Wildcard filters
  • Filtering on lookup columns

Basic Filter

For instance, the query string below filters the Orders list view to show only items where Product is equal to Jetpack:


You must refer to columns by their internal name, which may be different from the display name.  Fields with spaces in their display name will certainly have different internal names.  For instance, the internal name for Order Number would likely be Order_x0020_Number.

Filtering Multiple Columns

Filters on additional columns can be appended with

&FilterField2=_____&FilterValue2=_____

And so on.

Multi-value Filters

To apply multiple filter values to a single column, the syntax is a little different:

&FilterName=______&FilterMultiValue=____;____;_____

Separate each filter value with a semi-colon ( ; ).  For instance, show only orders whose Product is Jetpack OR Prismatic Core:



Wildcard Filters

FilterMultiValue also supports partial matches.  Use the asterisk ( * ) symbol to indicate a wild card. For instance,

&FilterName=Product&FilterMultiValue=*jet*

shows all orders whose Product contains the string "jet":

Lookup Column Filters

In the examples above, Product is acutally a lookup field, and I've been filtering using the lookup value.  If the Product names are very long, or we just don't know the names, we'll have to filter by the lookup ID.  That is requires a little tinkering with the list.

First we have to bring the lookup ID over as a projected field.  Go to List Settings and edit the lookup column (Product in this example).  Under Additional Column Settings, make sure the ID field is being brought over.


This adds a field to the list called Product:ID, which we can now use to filter the list views.  Because the display name contains a colon ( : ), the internal name will be different.  In most cases, it will be Product_x003a_ID.

The following filter shows all items whose Product's ID is 4:


18 comments:

Awesome! exactly what I needed. Thanks!

Thanks. This saved my time :)

Can we filter multiple columns with multiple values?

Thank you very much, I serached since a while a way to make multiple filters and how to use the generic character '*'

How to search in multiple columns with multiple values in each column?

Hi, this article is very helpful, but something happens to me, querystring filter Works ok it shows the view filtered, but when i want to see the column filter options, for example Title column, shows me all the options, mean filters view, but shows all options in the menu filter for each column.....any ideas about this?

Hello, I love your post it really help and save alot of time. Just a quick question, how do you use column and value that has space in and special character eg "Column value=6HK6417 (574-31773711) and column name =House AWB/BL #"?

You need to refer to columns by their Internal Names, which will never contain spaces or special characters. There's a simple way to find the Internal Name if you don't know it. Go to the List Settings, and click into the column. Copy the entire URL, and decode it with an online tool (http://meyerweb.com/eric/tools/dencoder). The column's Internal Name will be at the very end of the URL.

Hi, This is very helpful! Can you also please tell me how to filter date & number columns?

This will not search lookup column where allow multiple values is checked - Getting an error. How can I search lookup column with multiple values allowed ?

How to use multifilter in Lookup columns?

It is not working if we have paging enabled in list view webpart

the greate article, it save me lot of time.

how can we filter multiple line of field in the list using FilterField and FilterValue

Love it! Thanks very much for these tips. Is it possible to use the wildcard to filter out values, i.e., NOT=cancel* ?

Post a Comment