SharePoint list view filtering with query string paramters


The reason why this post says “advanced filtering” is because a while ago I wrote a post which explains how to pass query string parameters to a list view to do basic filtering; the only thing is that method only allow for exact match and not “contains”, “begins with” etc. So this time, I’ll show you how you can pass a query string parameter to a view and do any sort of filtering just as if it was a query defined in a list view UI.

Here is the example of my end result – I pass in a parameter “ren” and it’s matched against a file name in a document library called “rename.txt”
query string filtering end result

Let’s see how to make this happen.

First, chose a list you want to do a custom filter on and create a new view with SharePoint UI.
Here, define how you want the view to look like and how it should be filtered. For example below I have a view in a document library which allows to filter the name of the document based on some custom keyword called “{Param1}” … We’ll talk what this custom param is all about.

view filtering options

By the way, you can define several filters if you like, there is nothing special about this method that will prevent multi-filter.

Next, open a SharePoint Designer and navigate to your list, open the new view you created as “Edit in Advanced Mode”.

newly created view

Locate the section which looks like this:
editing view in advanced mode

Add a new item to the ParameterBinding list as you can see above:

<ParameterBinding Name="Param1" Location="QueryString(param1)" DefaultValue=""/>

In my case, I added a new parameter called “Param1″ and its tied to a query string parameter called “param1″ – this later one is how the parameter is going to be referenced in a query string and can be different from the “Param1″.

While you’re editing your view, scroll down a bit till you see the section where the view query is defined, it’ll be right below the
<ParameterBinding Name="Param1" Location="QueryString(param1)" DefaultValue=""/>

Since you have already defined the filter parameter (the “[Name] [contains] “Param1″, in my case) when you created the view you should see it in the XML of the view like this:

filtering by param in a view XML

You’re all done, now you can save this view and call it with the specified query string parameter, in my case “param1″ and you will see only the files with names containing the letter passed.

Gotchas: One thing I will mention here is that if you don’t pass parameter in here, you will not get any results even if you document library is filled with documents. There are few ways to deal with it; one of the ways is to define a second filter which will always be “true” and make the OR relationship between both filters. I’ll let you decide your course of actions. Technically you would be using this specialized filter view for specific filtering requirements (say in a Page Viewer webpart etc) and All Documents view for general browsing purposes.

Published by Aryan Nava

Founder of "BlockchainMind", CTO for two Blockchain startup during 2018, Cloud/DevOps Consultant and Blockchain Trainer

3 thoughts on “SharePoint list view filtering with query string paramters

  1. Thank you for your article.
    It works well on PC view.
    But it doesn’t work on Mobile view (both classic view and contemporary view)

    How can I do same thing on mobile view?

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: