Yes! You can add multiple filters to a List view webpart

Posted on September 18, 2009. Filed under: Data View Webparts | Tags: , , , |

Have you recently tried to apply filters from the Column Header dropdowns in any list!!!!

(After the SP2, the Column header drop downs now have the unique list field values to select and filter list items)

Try it, and see the reflected URL in the browser –

Something like this – “http://xx /test/SalesContactNewUI_Test.aspx?View={FB06F5EA-EDD3-433A-9FF4-C2CBEB88FF60}&FilterField1=Line%5Fx0020%5Fof%5Fx0020%5FBusiness&FilterValue1=Auto%20Dealer%20Commercial%20Services&FilterField2=Country&FilterValue2=Europe”

The highlighted parameters in the above URL can be utilized to apply a filter on any List view webpart.

Let’s pick the same business scenario as in my previous post https://sharepointxperiments.wordpress.com/2009/08/03/multiple-filters-on-a-data-view-webpart/ .

Get your dropdowns data bounded to the look up lists, add the resp list webpart to the page and add the JavaScript method for the button click event.

Though it’s a pretty quick way of doing, we would miss the flexibility data views provide.

JavaScript –

function ApplyFilter(event)

{

var DropDownFilter1 = getTagFromIdentifierAndTitle(’select’,’DropDownFilter1′,”);

var Filter1 = DropDownFilter1.value;

var DropDownFilter2 = getTagFromIdentifierAndTitle(’select’,’DropDownFilter2′,”);

var Filter2 = DropDownFilter2.value;

var url = “http://” + document.location.host + document.location.pathname;

              if(Filter1 != “All ” && Filter2 != “All “)

             {

  document.location.href = url +”?View={FB06F5EA-EDD3-433A-9FF4-C2CBEB88FF60}&FilterField1=Line%5Fx0020%5Fof%5Fx0020%5FBusiness&FilterValue1=” +Filter1 +”&FilterField2=Name&FilterValue2=” +Filter2 ;

             }

             if(Filter1 != “All ” && Filter2 == “All “)

            {

   document.location.href = url +”?View={FB06F5EA-EDD3-433A-9FF4-C2CBEB88FF60}&FilterField1=Line%5Fx0020%5Fof%5Fx0020%5FBusiness&FilterValue1=” +Filter1 ;

              }

             if(Filter1 == “All ” && Filter2 != “All “)

            {

   document.location.href = url +”?View={FB06F5EA-EDD3-433A-9FF4-C2CBEB88FF60}&FilterField1=Name&FilterValue1=” +Filter2 ;

              }

             if(Filter1 == “All ” && Filter2 == “All “)

 {

 document.location.href = url;

 }

 return false;

}

 

function getTagFromIdentifierAndTitle(tagName, identifier, title)

{

var len = identifier.length;

var tags = document.getElementsByTagName(tagName);

for (var i=0; i < tags.length; i++)

{

var tempString = tags[i].id;

if (tags[i].title == title && (identifier == “” || tempString.indexOf(identifier) == tempString.length – len))

{

return tags[i];

}

}

return null;

}

Read Full Post | Make a Comment ( 2 so far )

    About

    Xperiments n Xperiences. For the Last 5 years I have been providing variuos portal solutions (SharePoint focused) to my clients and now I intend to publish few of those solutions 'Not As It Is', which might help you. – Mash

    RSS

    Subscribe Via RSS

    • Subscribe with Bloglines
    • Add your feed to Newsburst from CNET News.com
    • Subscribe in Google Reader
    • Add to My Yahoo!
    • Subscribe in NewsGator Online
    • The latest comments to all posts in RSS

    Meta

Liked it here?
Why not try sites on the blogroll...