This project has moved and is read-only. For the latest updates, please go here.

Javascript pass variable to filter webpart

Apr 16, 2013 at 11:24 AM

This is not a SPServices question specifically but more general - SPServices might be used to help me what I need to do. I already use SPServices heavily throughout my site.

I need to be able to pass a javascript variable to a filter webpart which then filters a list view on a page. Does anyone know if this is possible somehow? If not I guess I will have to recreate the view using SPServices and pass in the filter directly.

Many Thanks,
Apr 16, 2013 at 1:22 PM

Where do you want to pass the variable from? Another page?

Apr 16, 2013 at 1:48 PM

No, what I am looking to do is upon first load of the site present the user with a drop down choice and save this choice in a list beside the username.

When the user visits the site in future I will use SPServices to pull this value into a variable and then was hoping to pass this to the list view web part. I had initially thought that I could simply append it onto a GET var on every link and pass it though a query string filter webpart. However most links (for individual list item view pages) on my SharePoint get redirected through an aspx file in the /_layouts/ folder which means that by the time the page loads this GET var has been stripped from the URL.

Any ideas?

Apr 16, 2013 at 3:13 PM
I think I'd probably use a cookie rather than saving the value into a list, just for performance reasons. But if you do write it into a list, just use GetListItems to read the value from the list on page load.

Apr 16, 2013 at 4:41 PM
Any ideas on how to send a JS variable to a webpart filter? Not sure if there is a JS call on the SP side that I can tap into?
Apr 16, 2013 at 4:49 PM
You'd need to build the filtering yourself in jQuery. There are several examples here on Codeplex. One that I've used in the past (but was built for SharePoint 2007) is jvossers' SharePoint InstantListFilter ( but there are others.

You'll need to consider whether client side filtering is going to work well given your data, of course. If there is too much data for it to be feasible, then consider using a Filter Web Part and a Web Part Connection, or if you are comfortable customizing XSL, a DVWP.

Apr 17, 2013 at 8:47 AM
Thanks! I wouldn't need the users to be able to filter like in your example above this could be done once on page load.

There is no way you know of interacting with a filter web part using javascript? If not I guess I will have to recreate it and use SPServices to display and filter the data.
Apr 17, 2013 at 3:30 PM
I'm assuming that you're on SharePoint 2010. The Filter Web Parts tend to do postbacks to send values, so probably not what you're looking for.

You sort of lost me with the whole GET var thing.