Sharepoint List View Filter Custom Webpart

Recently I have had a business requirement to create a search facility that would allow end users to search within SharePoint list view. This can be a particular important requirement specially when your list items are over (200+) and clicking through list view paging is impracticle usability to get to the item end user is looking for. Perhaps, your end users want to search a list item based on a value in one of the columns.

This is where I ended up resorting to creating a Custom Webpart that would work in conjunction with Out of The Box ListView Webpart allowing end users to quickly type in something they are looking for against a desired column and get relevant results.

The principal is really simple.

Utilising the capability of a Visual Webpart (it already incorporates a .ascx user control) and constructing desired url’s on button click events, you can easily implement a bespoke functionality that is scalable enough to manage yet quintessentially effective for end users.

Before, I can dip into the actual development, let’s take a moment to understand SharePoint 2010 List View Filtering.

In a nutshell, ListView Filtering is a criteria based filtering of list items present in a view (allitems.aspx or customview.aspx).

Lets explore the following key ListView Filter workings *pay attention to syntax

Single Column Filtering
http://url/list/Allitems.aspx?FilterField1=ColumnInternalName&FilterValue1=abc

Single Column Filtering with more than one value to look for
http://url/list/Allitems.aspx?FilterName=ColumnInternalName&FilterMultiValue=abc;def;xyz

Single Column Filtering with wildcard character (good if you have a description type column)
http://url/list/Allitems.aspx?FilterName=ColumnInternalName&FilterMultiValue=*abc def*
// you can use space as well in the above

Two Separate Column Filtering
http://url/list/Allitems.aspx?FilterField1=ColumnInternalName&FilterValue1=abc&FilterField2=ColumnInternalName2&FilterValue2=uvw

Two Column Filtering with one column filter and another multiple values
I hope you got the point 😀 Feel free to mix these up and make sure the syntax is correct.

Now, having pinned these concepts down creating a visual list view search webpart is fairly straight forward.

Create a visual webpart using Visual Studio 2010 SharePoint Visual Webpart Template. Add a DropDownList control to your .ascx file with desired columns and make sure you have the following nested inside your dropdownlist control.


<asp:DropDownList ID="CriteriaSelector" runat="server">
<asp:ListItem Text="Region Code" Value="<strong>Region_x0020_Code</strong>"></asp:ListItem>
' It is important to have your columns internal names to ensure accurate references are made to the columns.
' I am using Region Code here but you can use your own desired columns.

</asp:DropDownList>
 <asp:Button ID="Search" runat="server" Text="Search" />

Inside the button click event, construct your new url by adding required filtering constucts and appending them to the end of the url. You can use HttpContext.Current.Response.Redirect() for redirecting end user to the same page but with added filtering constructs.

Ensure you are updating your internal column names to cater for end users renaming a column or have deleted a column. You can create this handy custom filter webpart with added properties that will allow end users or sharepoint administrators to simply add your webpart and populate the column properties to make everything work synchronously without repetitive deployments.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s