Javascript pass variable to filter webpart

Apr 16, 2013 at 10:24 AM
Hi,

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,
Michael
Coordinator
Apr 16, 2013 at 12:22 PM
Michael:

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

M.
Apr 16, 2013 at 12:48 PM
Hi,

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?

Thanks,
Michael
Coordinator
Apr 16, 2013 at 2: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.

M.
Apr 16, 2013 at 3: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?
Coordinator
Apr 16, 2013 at 3: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 (https://instantlistfilter.codeplex.com/) 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.

M.
Apr 17, 2013 at 7: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.
Coordinator
Apr 17, 2013 at 2: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.

M.