I use the SharePoint List Filter web part on a page to control several Data View Web Parts.
How do I read the current value of the List Filter in Javascript?
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.
Sign up to join this communitySharePoint List Filter web part is rendered as input text field for displaying filter value:
<input type="text" readonly="readonly" id="{ClientID}_SpListPicker_SelectionBox" title="Selected values" >
and input hidden field for storing filter value:
<input type="hidden" id="{ClientID}_SpListPicker_Selection" value="{FilterValue}">
Below are demonstrated several ways how to retrieve filter value on the client side.
function getListFilterValueFromControl()
{
var j = jQuery.noConflict();
var filter = j("input[id$='SpListPicker_Selection']");
return filter.val();
}
ContextInfo
represents List Info structure on the client side.
Property overrideFilterQstring
contains filter string in the following format:
FilterField1={FilterName1}&FilterValue1={FilterValue1}..
function getListFilterValueFromContextInfo()
{
var filterFields = ctx.overrideFilterQstring.split('&'); //
if(filterFields.length > 1)
{
return filterFields[1].split('=')[1];
}
return null;
}
ExecuteOrDelayUntilScriptLoaded(getListFilterValueFromControl, 'SP.js');
And if you have multiple list filter webparts in your page, here is how to access the value of each of them
$("div.ms-WPBody div div:eq(0) span input").val();
for your 1st webpart
$("div.ms-WPBody div div:eq(1) span input").val();
for your second webpart, and so on
Another method I just found after more research:
$(document).ready(function() {
var filterValue = $("div.ms-WPBody div div span input").val();
if (filterValue != null) {
alert("filter value is: "+$("div.ms-WPBody div div span"));
}
});
vgrem provided a more beautiful version though ;)