Home > C#, MOSS 2007, SharePoint, SharePoint 2010 > SharePoint 2010: Basic List search / filter WebPart

SharePoint 2010: Basic List search / filter WebPart


I have created a very simple SharePoint list search / filter WebPart which was inspired by the following blog post. This WebPart allows you to search records in a list where a selected field contains a specified text. It is useful in scenarios where you dont have SharePoint Search setup and just need a simple way of performing some search operations in a SharePoint List.

Adding the web part to SharePoint List View

Simply drop this web part on top of a page that contains a SharePoint View and it will allow you to apply a very simple search criteria.

The screenshot below shows the WebPart in action:

Main view of the List Search WebPart

The field name DropDownList allows you to select from the fields that are present in the view. Once you select the field and add the text to search by, the relevant results are displayed:

Screenshot showing search results

You can also specify multiple text values by seperating the text with a semi-colon (;):

Screenshot showing search results, multiple text criteria

In the above example the specified criteria will display all the records where the manufacturer’s name contains ‘Honda’ OR ‘Audi’. The screenshot below shows the pagination working as expected:

Screenshot showing search results, multiple text criteria

Adding the web part to a page with an XsltListViewWebPart

You can also add this web part to a page that contains an XsltListViewWebPart. The web part will automatically detect that it has been added to a page (rather than a List View) and display a message asking you to select an XsltListViewWebPart that you would like to apply the filters to:

The screen shot below shows how to select the XsltListViewWebPart:

You can download the solution by clicking on the link below:

SharePoint WSP Download link

You can view the codeplex project site by clicking on the link below:

Codeplex Project Site

Please note that this is setup as a Farm Solution and not a Sandboxed Solution therefore it will not work if you deploy it to the SharePoint Solutions Gallery, you need to deploy the SharePoint Solution via Central Administration, via stsadm commands or via PowerShell commands.

How to it works

On a page that contains a ListViewWebPart you can apply filter by adding a couple of query strings:

  • FilterName
  • FilterMultiValue

In our example, when a user types ‘honda’ and then clicks on the search button we simply append ‘?FilterName=LinkTitle&FilterMultiValue=*honda*;’ to the query string and redirect the user to that page. Please note that ‘LinkTitle’ is the internal name of the ‘Manufacturer’ field.

The * in the *honda* is used to do a wildcard search (contains). If you would like to search for multiple texts you can seperate them by a semi-colon for example ‘FilterMultiValue=*honda*;*audi*;’ will search for records where the ‘Manufacturer’ name either contains ‘honda’ or ‘audi’. If you would like to search for an exact match rather than apply a contains filter then simply remove the *’s from the filter value text.

Although, this WebPart does not allow you to filter / search by more than one field this is very much possible. To apply filters on additional fields you simply need to append ‘FilterField1=Model&FilterValue1=Accord’ to the URL. You can apply further filters by incrementing the number i.e. FilterField2, FilterField3 …. and so on. I am not sure if there is a limit on this.

Please note that I haven’t found a way to get the wildcard search to work with this (multiple filters) approach.

Building the WebPart

In your Visual Studio solution (assuming you have created a Blank SharePoint Project) add a ‘Visual WebPart’. A Visual WebPart loads a UserControl that contains most of the code. Below is the code of the .ascx file:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ListSearchUserControl.ascx.cs"
    Inherits="Exaction.ListSearch.WebParts.ListSearch.ListSearchUserControl" %>
<script type="text/javascript" src="/_layouts/Exaction.ListSearch.Javascripts/jquery.min.js"></script>
<table>
    <tr>
        <td>
            <strong>Search Criteria:</strong>
        </td>
        <td>
            <asp:TextBox ID="TbSearchText" runat="server" Width="300px"></asp:TextBox>
        </td>
        <td>
            &nbsp;
        </td>
        <td>
            <strong>Field name:</strong>
        </td>
        <td>
            <asp:DropDownList ID="DdlListFields" runat="server">
            </asp:DropDownList>
        </td>
        <td>
            &nbsp;
        </td>
        <td>
            <div align="right">
                <asp:Button ID="BtnSearch" runat="server" OnClick="BtnSearch_Click" Text="Search" />
                <asp:Button ID="BtnClearFilter" runat="server" Visible="false" OnClick="BtnClearFilter_Click"
                    Text="Clear Criteria" />
            </div>
        </td>
    </tr>
</table>
<script type="text/javascript">
    $(document).ready(function () {
        var base_RefreshPageTo = RefreshPageTo;
        RefreshPageTo = function (event, url) {

            var filterName = getQuerystring('FilterName');
            var filterValue = getQuerystring('FilterMultiValue');
            var newUrl = url + '&FilterName=' + filterName + '&FilterMultiValue=' + filterValue;
            if (filterName != '' && filterValue != '') {
                base_RefreshPageTo(event, newUrl);
            }
            else {
                base_RefreshPageTo(event, url);
            }
            return;
        }
    });
    function getQuerystring(key, default_) {
        if (default_ == null) default_ = "";
        key = key.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regex = new RegExp("[\\?&]" + key + "=([^&#]*)");
        var qs = regex.exec(window.location.href);
        if (qs == null)
            return default_;
        else
            return qs[1];
    }
</script>

The code above is pretty self-explanatory but very briefly it contains the UI elements (TextBox, Labels, DropDownList and Buttons) and some jQuery. The jQuery code overrides the ‘RefreshPageTo’ SharePoint javascript function. This is basically to get our filtering to work with pagination. If you have a SharePoint List View that is displaying paginated date to you then clicking on the next or previous page calls the ‘RefreshPageTo’ JavaScript function. The problem is that when this function is called it clears the querystrings we use to filter the data. To ensure that the filtering is maintained we override this function, modify the URL ensuring the filtering querystrings are present and then pass it in as the second parameter to the function.

using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Collections.Specialized;
using Microsoft.SharePoint;
using System.Collections.Generic;
using Exaction.ListSearch.UI.Entities;
using System.Text;

namespace Exaction.ListSearch.WebParts.ListSearch
{

    /// <summary>
    /// User control that deals with the registration process
    /// </summary>
    public partial class ListSearchUserControl : UserControl
    {

        /// <summary>
        /// Gets the share point list field items.
        /// </summary>
        /// <param name="filterCriteria">The filter criteria.</param>
        private List<OptionEntity> GetSharePointListFieldItems()
        {
            List<OptionEntity> fieldItems = new List<OptionEntity>();
            fieldItems = new List<OptionEntity>();
            OptionEntity item;
            SPField field;
            StringCollection viewFieldCollection = SPContext.Current.ViewContext.View.ViewFields.ToStringCollection();
            foreach (string viewField in viewFieldCollection)
            {
                field = SPContext.Current.List.Fields.GetFieldByInternalName(viewField);
                item = new OptionEntity();
                item.Id = field.InternalName;
                item.Title = field.Title;
                fieldItems.Add(item);
            }
            return fieldItems;
        }
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            List<OptionEntity> items = GetSharePointListFieldItems();
            DdlListFields.DataSource = items;
            DdlListFields.DataTextField = "Title";
            DdlListFields.DataValueField = "Id";
            DdlListFields.DataBind();
        }
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load"/> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs"/> object that contains the event data.</param>
        protected override void  OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (!IsPostBack)
            {
                if (Request.QueryString["FilterName"] != null)
                {
                    DdlListFields.SelectedValue = Request.QueryString["FilterName"].ToString();
                }

                if (Request.QueryString["FilterMultiValue"] != null)
                {
                    TbSearchText.Text = Request.QueryString["FilterMultiValue"].ToString().Replace("*", "");
                    BtnClearFilter.Visible = true;
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the BtnSearch control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void BtnSearch_Click(object sender, EventArgs e)
        {
            string redirectUrlFormat = "{0}?FilterName={1}&FilterMultiValue={2}";
            string[] selectionCollection = TbSearchText.Text.ToString().Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries);
            StringBuilder sbValues = new StringBuilder();
            foreach (string selection in selectionCollection)
            {
                sbValues.Append("*" + selection.Trim() + "*;");
            }

            string urlToRedirectTo = string.Format(redirectUrlFormat, Request.Url.GetLeftPart(UriPartial.Path), DdlListFields.SelectedValue, sbValues.ToString());
            Response.Redirect(urlToRedirectTo);
        }
        /// <summary>
        /// Handles the Click event of the BtnClearFilter control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        protected void BtnClearFilter_Click(object sender, EventArgs e)
        {
            Response.Redirect(Request.Url.GetLeftPart(UriPartial.Path));
        }
    }
}

The code behind above initialises the controls and handles the Search and Clear Search Criteria Button click events.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Exaction.ListSearch.UI.Entities
{
    public class OptionEntity
    {
        #region "Fields"
        public string Id { get; set; }
        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        public string Title { get; set; }
        #endregion

        #region "Constructor"
        public OptionEntity()
        {
        }
        #endregion
    }
}

We set a collection of the OptionEntity items as the DataSource of the Field name DropDownList.

That is basically it. In this simple manner you have a WebPart that you can drop on top of any List View and apply some basic free text Filterting.

Known issues

There are two minor known issues which I haven’t found a solution for yet:

  • Adding the WebPart on top of the page of a List View takes the focus away from the ListViewWebPart which in turn hides the ribbon. Once you click on the ListViewWebPart and focus on it then the ribbon becomes visible.
  • This WebPart does not work properly with Views that use groupings that are collapsed by default, it works if the groupings are expanded by default
  • As pointed out by Goran (see comments) it might not work with External SharePoint Lists

I hope you find this WebPart useful. Please post your comments and feedback and it would be helpful if you can rate this post.

  1. Susanne
    May 4, 2012 at 9:24 am

    Does it work on managed metadata column values?

    • jasear
      May 9, 2012 at 8:26 pm

      I have never tried it with them but I dont see any reason why they shouldn’t work with them.

  2. Areon Jackson
    May 7, 2012 at 4:46 pm

    Hello, thank you for this information. This looks exactly like what I’m looking for. Question: does this filter the entire list, even content in the list that is not displayed? For instance, if the list was diplayed 30 of 1000 items would the entire 1000 items be filtered?

    • jasear
      May 9, 2012 at 8:28 pm

      Yes it filters the entire list. As I mentioned in the post above, it should work with pagination.

  3. Goran
    June 15, 2012 at 12:51 am

    Hello, it looks like this web part doesn’t work with external list. I works fine with SP native list, however, when I search external list, the list gets refreshed, but nothing changes. All rows are still visible.

    Are you aware of this issue?

    • jasear
      June 18, 2012 at 3:47 pm

      Goran, I haven’t tried it with external lists before. Thanks for the feedback I will update the blog post.

  4. June 15, 2012 at 4:11 pm

    Hi I tried adding this webpart and I found an unexpected error while adding this webpart.
    I checked the logs. Something in the GetSharePointListFieldItems method is erroring

    Please help me with that !!

    • jasear
      June 18, 2012 at 3:49 pm

      Hemant, can you please send me the full stack trace of the error? It would also help if you can send me your SharePoint List Template.

      As you can see from the comments above the WebPart works for most people but I think in your case it could be something specific to your list that is causing the error.

      Alternatively, as you have access to the source code you could debug to try and figure out what is causing the issue. In that case, I would be grateful if you could let me know what caused the issue once you have fixed it.

      • Kari Nafziger
        September 6, 2012 at 7:54 pm

        Hello! I am getting the same error. Here is the stack trace. Can you help?

        [NullReferenceException: Object reference not set to an instance of an object.]
        Exaction.ListSearch.WebParts.ListSearch.ListSearchUserControl.GetSharePointListFieldItems() +105
        Exaction.ListSearch.WebParts.ListSearch.ListSearchUserControl.CreateChildControls() +15
        System.Web.UI.Control.EnsureChildControls() +145
        System.Web.UI.Control.PreRenderRecursiveInternal() +60
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Control.PreRenderRecursiveInternal() +223
        System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3393

  5. July 16, 2012 at 4:25 pm

    The following URL doesn’t work
    [myServer]/SitePages/testList/AllItems.aspx?FilterName1=Title&FilterMultiValue1=*on*&FilterName2=value&FilterMultiValue2=*star*

    Can you tell me how to use multiple FilterName in URL?

    • jasear
      July 16, 2012 at 7:59 pm

      Raihan,

      To apply multiple filters it needs to be in the following format:

      FilterField1=Title&FilterValue1=Hello&FilterField2=Status&FilterValue2=Closed

      This doesn’t seem to work with wildcard search though and only seems to work for exact matches.

  6. July 17, 2012 at 5:09 pm

    It’s a very good approach. But one question, does it work with datetime field? If so, what’s the format of the query string for that? Thanks.

  7. July 26, 2012 at 7:16 am

    when i was solution which is on codplex. It will not showing activate button and giving me warning message You should only activate this solution if you trust this solution. An activated solution can read, modify and delete your data and activate button is gray out can.
    can you help me in this

  8. Chris
    August 2, 2012 at 12:41 pm

    Hi, great idea to create such a web part. Unfortunately i can’t activate your solution at the solution catalogue. The “Activate” Button is disabled. Thanks in advance.

  9. MikeD
    August 13, 2012 at 7:36 am

    Hello, When I add this webpart to a page – I also recieve an error message on the page.
    (perhaps similar to hemantgupta above in the blog). If you will contact me – I would be happy to spend some time trouble shooting this with you. Thanks.

    • jasear
      August 13, 2012 at 9:49 pm

      Hi Mike,

      Can you please email me a screenshot of the error message you recieve?

      My Email address is: jalil.sear@gmail.com. Can you also let me know what is the template (e.g. Document Library, Custom List e.t.c.) of the list you are trying to add this WebPart to?

      Thanks

  10. PatrickB
    August 21, 2012 at 2:13 pm

    Have you been able to come up with a solution for the error in loading the webpart. I’m getting the exact same error when uploading the solution.

    • jasear
      August 21, 2012 at 3:06 pm

      Hi,

      Sorry but I havent been able to because no one has send me exact description of this “exact” error.

      If someone can send me 1) Full stack trace and 2) A screen shot with 3) Steps to reproduce the error I might be able to fix the problem if the problem is indeed with the WebPart.

      My email address is: jalil.sear@gmail.com.

      • jasear
        August 22, 2012 at 9:13 pm

        Hi Patrick,

        Thanks for sending me the required information.

        This is a farm solution and not a sandboxed solution therefore it will not work if you upload it to the SharePoint Solution Gallery.

        I have made the complete source code and the Visual Studio Solution available, so if you or anyone else wants to make changes to turn it into a sandboxed solution then by all means do so.

        I hope this explains it. I have also updated the blog post with this.

      • PatrickB
        September 6, 2012 at 5:01 pm

        Jalil
        Attempting to upload this solution via the Sharepoint PowerShell using the following command: stsadm -o addsolution -filename c:\Exaction.ListSearch.wsp and it is giving me the following error (Object reference not set to an instance of an object. The Solution installation failed. It seems that others have been able to get this solution to work and I would like to follow the steps they took to get this solution installed.

        Thanks – Patrick

  11. August 28, 2012 at 5:19 pm

    Works like a charm. You are great brother… I have bookmarked you…

  12. Aretha
    September 2, 2012 at 5:06 am

    Post writing is also a excitement, if you be acquainted with afterward you can write
    or else it is difficult to write.

  13. Taylor Bouman
    September 4, 2012 at 7:18 pm

    Sent an email with details on the error. Hopefully you can help me out 🙂

  14. jasear
    September 7, 2012 at 11:55 am

    PatrickB :

    Jalil
    Attempting to upload this solution via the Sharepoint PowerShell using the following command: stsadm -o addsolution -filename c:\Exaction.ListSearch.wsp and it is giving me the following error (Object reference not set to an instance of an object. The Solution installation failed. It seems that others have been able to get this solution to work and I would like to follow the steps they took to get this solution installed.

    Thanks – Patrick

    Kari Nafziger :

    Hello! I am getting the same error. Here is the stack trace. Can you help?

    [NullReferenceException: Object reference not set to an instance of an object.]
    Exaction.ListSearch.WebParts.ListSearch.ListSearchUserControl.GetSharePointListFieldItems() +105
    Exaction.ListSearch.WebParts.ListSearch.ListSearchUserControl.CreateChildControls() +15
    System.Web.UI.Control.EnsureChildControls() +145
    System.Web.UI.Control.PreRenderRecursiveInternal() +60
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Control.PreRenderRecursiveInternal() +223
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3393

    Taylor Bouman :

    Sent an email with details on the error. Hopefully you can help me out :)

    Hi Guys,

    This is indeed an issue. It occurs when you try to use the web part on a page where you have an XsltListViewWebPart on the page. If you add the web part on a list view then it works perfectly.

    I have created a fix for this and I have updated the download link in the blog. I have also updated the blog with instructions on how to get the filter web part to work with an XsltListViewWebPart.

    Thanks for reporting this guys and please do let me know if you encounter any further issues.

    • PatrickB
      September 7, 2012 at 7:07 pm

      Still getting the same error Object reference not set to an instance of an object. Not sure if I’m ever at the point to where I can actually attempt to activate the wsp file because I can’t even get this solution to step through the stsadm commands…. Using the following command in Sharepoint 2010 Management Shell…

      stsadm -o addsolution -filename c:\Exaction.ListSearch.wsp

      The next command I will be using if the first one suceeds is

      stsadm -o deploysolution -name Exaction.ListSearch.wsp -immediate

      If I’m doing something wrong let me know. Otherwise I’m at an utter loss on how I’m able to upload other solutions just not yours…

      Thanks – PB

  15. jasear
    September 7, 2012 at 8:59 pm

    PatrickB :

    Still getting the same error Object reference not set to an instance of an object. Not sure if I’m ever at the point to where I can actually attempt to activate the wsp file because I can’t even get this solution to step through the stsadm commands…. Using the following command in Sharepoint 2010 Management Shell…

    stsadm -o addsolution -filename c:\Exaction.ListSearch.wsp

    The next command I will be using if the first one suceeds is

    stsadm -o deploysolution -name Exaction.ListSearch.wsp -immediate

    If I’m doing something wrong let me know. Otherwise I’m at an utter loss on how I’m able to upload other solutions just not yours…

    Thanks – PB

    Patrick,

    That error sounds like a permissions error to me. Are you sure you are using the same user to deploy this solution that you are using to deploy the other solutions (that are succeeding)?

    I would suggest that you try to run the stsadm command again and as soon as it fails check in the SharePoint ULS logs to see if it gives you more details.

    I tried the same stsadm command on my environment and it worked perfectly so please see if the log file gives you more information.

  16. Johnathan Bailey
    September 7, 2012 at 9:17 pm

    Exactly what I was looking for. Works perfectly!

  17. Taylor Bouman
    September 10, 2012 at 12:36 pm

    Very Excellent. Thank you for your incredible response time! Is the recent code change displayed in the source code if downloaded in Codeplex?

    • jasear
      September 10, 2012 at 12:53 pm

      Taylor,

      Try the ‘SharePoint WSP Download link’ in the blog to download the latest Solution.

      Please let me know if it fixes the issue.

      • Taylor Bouman
        September 10, 2012 at 12:56 pm

        Your changes properly fixed my issue. Thank you very much.

  18. Jason Poirier
    September 24, 2012 at 1:14 pm

    Hi,

    I must be a huge noob but I have a list problem. I added the solution and activated the feature. When I go on the page where I want to add the webpart and edit it, the webpart is not in the list of available webparts.

    Anyone know what I am doing wrong

    • jasear
      September 24, 2012 at 8:33 pm

      Jason,

      Not sure what has happened but I would try to deactivate and then activate the web part feature to see if it appears.

      Can you also send me a screenshot of what you see when you try to add the web part (i.e. when you dont see the web part in the list)? Please email it to jalil.sear@gmail.com.

  19. Mitesh
    October 3, 2012 at 5:31 pm

    Does it work with document library as well. I have few folder with Field “Name”. I have added the search and the filter criteria is showing up properly. But when I try to search it just refresh the page. nothing else

    • jasear
      October 5, 2012 at 10:51 am

      Hi Mitesh,

      It does work with Document Libraries but only on the filterable fields (i.e. name of the document, title, multi choice fields etc.)

      However, it does not work with folders. It is a basic list search web part so sadly I feel that getting it to work with folders is out of the scope for this web part.

      I am working on a slightly more advanced list search web part which I am hoping to make available some time in the future and will keep this requirement in mind for that.

  20. Scott Freeland
    October 8, 2012 at 9:32 pm

    The update for XsltListViewWebPart works great. Are you planning on updating the source on Codeplex?

    • jasear
      November 7, 2012 at 12:53 pm

      Hi Scott,

      Sorry for the delay, I have updated the source code on codeplex, please download and let me know if you encounter any issues.

      • Scott Freeland
        November 7, 2012 at 2:46 pm

        Thanks!

      • Scott Freeland
        November 7, 2012 at 4:01 pm

        Hey I think you forgot to check in ListSearchEditorPart.cs. It’s missing in the new project.

      • jasear
        November 7, 2012 at 5:48 pm

        Try again it should be there now.

  21. sowjanya
    October 11, 2012 at 8:18 pm

    Hi…Thanks for the web part, It will be great if you can update the source in codeplex, it’s working fine if I deploy .wsp,but I’m getting null reference exception when I have tried to use the source code, it’s not showing up the xsltlistview choose option in the toolpane. any idea on this??

    • jasear
      November 7, 2012 at 12:54 pm

      Hi,

      I have updated the source code on codeplex please try downloading it now.

  22. October 22, 2012 at 10:01 pm

    Hi, I´m Omar Juárez and your post was helpful for me, It was exactly what I was looking for! Thanks !!!!!!!

  23. Satish
    November 5, 2012 at 5:39 am

    Hi, Thanks for the useful post. I am trying to get sandbox solution for the same requirement, would you be able to advice what changes I might need to get this work as sandbox solution?

    • jasear
      November 7, 2012 at 1:33 pm

      Hi Satish,

      Unfortunately, it would require quite a lot of changes (if it is even possible) to get it to work.

      The web part uses some SharePoint APIs which are not available in a sandbox solution, I would look at the SharePoint Client Object Model to try and get it to work in a sandbox solution.

  24. may7700
    November 29, 2012 at 4:40 pm

    Hi there.
    If i have multiple search criteria then does it work if url passes SharePoint limit of 250 characters?
    Regards;
    Mayur.

    • jasear
      November 30, 2012 at 12:16 pm

      I have not tried this but I think there might be an issue if your url passes the SharePoint limit.

  25. BigTrollDad
    November 29, 2012 at 6:56 pm

    I tried this by adding the web part to a document library view page. The filtering is not working. I notice that the query parameters use the FilterName and FilterMultiValue
    Instead of FilterField1 & FilterValue1 which is used out of the box. Why is this? Was this for the other scenario for a generic page with list web parts? For that scenario, how does one specifically get the targetted xslt list view web part to filter with those query parameters?

    • jasear
      November 30, 2012 at 12:14 pm

      Hi,

      I have just tested this with a document library and it works on my end, I selected the ‘Name’ field and then entered the criteria and it displayed the filtered results.

      What field are you selecting to filter by? Secondly, does it work for you in a normal SharePoint List i.e. non-document library?

      The reason I am using FilterMultiValue instead of FilterValue1 is because (if my memory serves me right) it allows me to apply more than 1 filter criteria on a field. For example if I have a List called Cars and I want to search for all car names with H or S in the beginning then I can do that using FilterMultiValue but I dont think this can be done by using FilterValue1.

      FilterValue1 etc is useful if you want to apply filters on more than 1 field.

  26. Phil
    December 5, 2012 at 11:10 am

    Hi

    I already installed the Solution and it works great in my Lists. But sometimes, when i search for an item, the item will be found but i can´t edit the Item. That doesn´t happen with all records. The Buttons on the Top of the Page stay grey.
    When I select the Items without searching for them, everything is OK.

    Do you have an Ideas how to fix the Problem?

    Thank you.

    • jasear
      December 5, 2012 at 10:20 pm

      Hi Phil,

      I have just checked this and this is indeed an issue. It seems that using the FilterMultiValue approach results in some of the ribbon buttons getting disabled.

      I will have to look into this to see if I can find a possible solution but in the meantime you could work around this issue by adding the ‘Edit’ Field to your view which will allow you to Edit the item after search.

  27. Phil
    December 6, 2012 at 9:56 am

    Hi Jalil,

    It sounds good to me, that you became the same Error 🙂 I thought I was doing wrong in installing the solution.
    Can you please give a little workaround, how to create an extra Button to edit the Items.
    I went to Sharepoint Designer and then to Views. There I opend the AlltItems.aspx. At this Point I don´t know how to proceed.

    Thank you very much for your Time und Help.

    Grettings from Germany.

    • jasear
      December 6, 2012 at 10:23 am

      Hi Phil,

      Browse to your SharePoint List and select the View you want the Edit Icon to appear in, then from the ribbon click on the ‘Modify View’ button. From there in the columns section you will see a column called ‘Edit (link to edit item)’add this to your View and it will display an Edit Icon next to your list item which will allow you to edit items. Alternatively you could add the ‘Title (linked to item with edit menu)’ column and this will add the Title Field in your view which renders as a link with a context menu and from the context menu you can edit the item.

      Hope this helps.

  28. sowjanya
    January 7, 2013 at 9:40 pm

    Hi… is there any way I can search on the whole list at, instead of doing it on one column at once

    • jasear
      January 15, 2013 at 3:37 pm

      Hi,

      Unfortunately this Basic List Search Web Part doesnt allow you to do that, you will need to setup SharePoint Search for that.

  29. huhles
    January 31, 2013 at 8:36 pm

    Hello, this web part does exactly what I need! I can’t seem to get it to work, however. I keep getting the “Web part is not configured…select an XsltListViewWebPart…” message despite my having selected the list from the dropdown in the tool pane. I did notice a Javascript error which says “Object doesn’t support this property or method”, but I’m not sure which object it’s referring to. Have you heard of this sort of error occuring with the web part before? Thanks so much!

  30. February 19, 2013 at 2:39 pm

    For the Known issue:

    •This WebPart does not work properly with Views that use groupings that are collapsed by default, it works if the groupings are expanded by default

    If you add this javascript line in the code section right before it performs the search, it should auto expand all groups before searching for the keyword:

    $(“img[src*=’plus.gif’]:visible”).parent().click();

    I didn’t try it with your web part, but I have used this within other smaller javascript/jquery content editor based web parts with success…

    -Jeff

    • TedH
      April 16, 2014 at 3:14 pm

      I am considering using this. How would it work with a large indexed list which has over 10,000 rows? I am using grouping as well as restricting groups to 500 entries at a time. Is this search function restricted to searching only the data in the page (e.g. of the 500 entries in my case)?

  31. Randy
    March 19, 2013 at 2:24 pm

    Is this available in .webpart or .dwp format

  32. vlad
    March 31, 2013 at 11:47 am

    really nice
    many thanks for sharing this
    works great but i have 1 issue
    clicking search with an empty search criteria does not show the list but an exception error in that space
    any easy fix?
    nice would be if the search button is disable when there is no entry

  33. Scott Freeland
    April 11, 2013 at 9:23 pm

    Hi there, again. I noticed an interaction issue between your web part and pages with linked web parts. When ticking the arrow to select a linked item, the FilterName and FilterMultivalue parameters get nuked from the URL. The connection actually happens and linked web parts receive the parameter, but the XsltListViewWebPart reverts back to it’s default view.

    There’s probably a better way to fix it, but here’s a new OnLoad that checks for the parameters and puts them back in if they got nuked.

    protected override void OnLoad(EventArgs e)
    {
    base.OnLoad(e);
    if (!IsPostBack)
    {
    if (Request.QueryString[“FilterName”] != null)
    {
    DdlListFields.SelectedValue = Request.QueryString[“FilterName”].ToString();
    }

    if (Request.QueryString[“FilterMultiValue”] != null)
    {
    TbSearchText.Text = Request.QueryString[“FilterMultiValue”].ToString().Replace(“*”, “”);
    BtnClearFilter.Visible = true;
    }
    }
    else
    {
    // is postback. see if we need to append the url
    if (TbSearchText.Text != null)
    {
    if (this.Request.Url.ToString().Contains(“SelectedID=”) && !this.Request.Url.ToString().Contains(“FilterMultiValue=”))
    {
    string redirectUrlFormat = “{0}&FilterName={1}&FilterMultiValue={2}”;
    string[] selectionCollection = TbSearchText.Text.ToString().Split(new string[] { “;” }, StringSplitOptions.RemoveEmptyEntries);
    StringBuilder sbValues = new StringBuilder();
    foreach (string selection in selectionCollection)
    {
    sbValues.Append(“*” + selection.Trim() + “*;”);
    }

    string urlToRedirectTo = string.Format(redirectUrlFormat, Request.Url, DdlListFields.SelectedValue, sbValues.ToString());
    Response.Redirect(urlToRedirectTo);
    }
    }
    }
    }

  34. Indramani
    July 16, 2013 at 6:45 am

    Hi Guys,
    Same ! We want to SharePoint 2010: Basic Libary search / filter WebPart ( Document File )

    Please Help me…

    Thanks
    Indramani Gautam…

  35. Sanj
    August 7, 2013 at 4:10 pm

    Hi, I have installed this and it is working well. thanks for the effort you have done here. I have one question though. is there a way to choose only the selected columns of a list to appear in the filter drop down ?

    Thanks

    • jasear
      September 12, 2013 at 9:09 am

      Hi Sanj,

      Sorry for the late response. The drop down only displays fields that are present in the current view, so you can control what appears in the drop down by changing the view.

      If you require more flexibility then please feel free to alter the source code to suit your needs.

      • sanj
        September 16, 2013 at 11:14 am

        Hi,
        I only had one view for my list so I managed to alter the source code and now its working the way I wanted. its only showing the columns I wanted now.
        Thanks

  36. Mar
    September 12, 2013 at 12:31 pm

    Hello.

    It filters every list in the page. Haw can this be handled? I only need a certain list to be filtered.

    Thanks!

    • Mar
      September 12, 2013 at 12:49 pm

      How*

  37. Wan
    January 21, 2014 at 1:41 am

    Hello

    When I deployed this solution on https environment it’s getting error. Seems like the page is not refresh or it cannot pass the parameter to the url. Please help..

    Thanks.

  38. February 18, 2014 at 1:03 pm

    I read this paragraph fully about the difference of latest and earlier technologies,
    it’s remarkable article.

  39. February 22, 2014 at 1:41 pm

    Great weblog here! Additionally your website rather a lot
    up very fast! What web host are you the use of?
    Can I get your associate link on your host? I want my web
    site loaded up as fast as yours lol

  40. February 24, 2014 at 5:01 pm

    Hey! I just wanted to ask if you ever have any problems with hackers?
    My last blog (wordpress) was hacked and I ended up
    losing months of hard work due to no data backup.
    Do you have any methods to stop hackers?

  41. July 14, 2014 at 2:14 pm

    Thank you, that’s really useful!

  42. August 10, 2014 at 7:59 pm

    Having read this I believed it was very enlightening.
    I appreciate you spending some time and effort to put this informative article together.
    I once again find myself personally spending a lot
    of time both reading and commenting. But so what, it was
    still worth it!

  43. August 19, 2014 at 12:39 pm

    I am noow not positive thhe place you are getting yoiur information, but good topic.
    I needs to spend some time studying more or understanding more.
    Thanks for wonderful infrmation I used to be onn
    the lookout for this information for my mission.

  44. Ozgur
    September 19, 2014 at 8:55 am

    very good ,I tried it working nice ,thank you for your work

  45. September 27, 2014 at 12:10 am

    Nice answer back in return of this matter with real arguments and telling the
    whole thing about that.

  46. September 29, 2014 at 6:56 am

    When I originally commented I clicked the “Notify me when new comments are added”
    checkbox and now each time a comment is added I get four emails
    with the same comment. Is there any way you can remove me from that service?
    Bless you!

  47. Bashkim
    November 5, 2014 at 2:09 pm

    Great job, saved me so many times so much time

  48. Faronix
    December 9, 2014 at 2:51 pm

    Very good job!! I love it!! To be perfect, it could have the chance to change the 2 webpart field names and the button (to a diferent language)

  49. Faronix
    December 15, 2014 at 3:20 pm

    I have noticed that, if i search with empty field it always returns this error on refered list:

    Exception from HRESULT: 0x80131904

  50. Ted
    January 6, 2015 at 1:14 pm

    Have you found a solution to search/filter an external list?

  51. Irsath
    July 8, 2015 at 3:28 pm

    In our case, when i search for it everything is working like a charm. But many users are reporting that they are not getting the result from the list search. But the same results are displayed in the sharepoint search. I am using the farm admin account. This is really urgent and kindly let me know what needs to be done. Thanks in advance!!

  52. January 17, 2016 at 5:40 pm

    *Would you be interested in exchanging links?

  53. zdhiu
    February 19, 2016 at 4:22 pm

    I love this web part! I installed it to my huge SharePoint list (> 10K) and search by category perfectly! Just one thing: after search/filter, I got a list. But I cannot edit item from this list. The ‘Edit Item’ ribbon bottom, even ‘View Item’ bottom, are disabled. I have same results in IE, Chrom. Is something wrong in my side?

  54. July 19, 2016 at 8:52 am

    Hi Jalil,

    First of all thanks for such a great piece of code. The filter works perfectly with pagination as well. But the column dropdowns shows all the values where as it should be displaying only the values filtered out.

  55. November 3, 2016 at 2:15 pm

    Se requiere personal para trabajar como asesores call center de servicio al cliente y soporte técnico de importante empresa de Telecomunicaciones, turnos de ocho (8) horas fijas, todas la prestaciones de ley. Se solicita personal para realizar tarea de ventas y promoción en el área limítrofe de soacha,con el fin de activar servicios de capacitación y certificación en gestión de seguridad y salud en el trabajo, enviar hoja de vida con foto, no requiere experiencia ni margen de edad.

  1. December 7, 2012 at 1:09 am
  2. September 24, 2014 at 3:35 am
  3. June 8, 2015 at 7:45 pm
  4. July 25, 2016 at 1:38 am

Leave a reply to jasear Cancel reply