Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

up vote 7 down vote accepted

SharePoint 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.

Retrieve filter value from input hidden field (jQuery dependency)

function getListFilterValueFromControl()
{
    var j = jQuery.noConflict();
    var filter = j("input[id$='SpListPicker_Selection']");
    return filter.val();
}

Retrieve filter value from context info

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;  
}

Usage

ExecuteOrDelayUntilScriptLoaded(getListFilterValueFromControl, 'SP.js');
share|improve this answer
    
Thanks vgrem! That's just beautiful. –  masterjo Feb 13 '13 at 15:42
add comment

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

share|improve this answer
add comment

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 ;)

Source: http://social.msdn.microsoft.com/Forums/br/sharepointdevelopment/thread/60e6b32d-86a7-4ddc-8f7d-800b58ceb3f9

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.