How to search grid results based on user provided values?

Last post 11-21-2009 4:00 PM by sjnaughton. 19 replies.

Sort Posts:

  • How to search grid results based on user provided values?

    10-06-2008, 7:54 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    I would like a user to be able to enter some criteria in a search box and then have them click on a search button to filter the data using a "contains" logic and not an exact match.

     Anyone know if this is possible?

    I have downloaded the DynamicFilterRepeater and that works well, but you end up with one search box per colulmn...I would like to have one search box that columns could subscribe to and that would be filtered automatically.

    Not sure how to go about doing something like that...I'm still quite new to DD and I am still trying to get a grasp on the basic stuff.

    Regards,
    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-06-2008, 11:39 PM
    • Participant
      1,320 point Participant
    • scothu
    • Member since 12-10-2007, 1:54 AM
    • Redmond, WA
    • Posts 272
    • AspNetTeam
      Moderator

    You should check out the filtering work done by Josh Heyse: http://www.codeplex.com/DynamicDataFiltering/Release/ProjectReleases.aspx?ReleaseId=16684, and his blog: http://blogs.catalystss.com/blogs/josh_heyse/.

    We are working on something in the same vein as this that will let you declaratively be able to add Linq expressions to the DataSource control which will let you do things like this that are very difficult to do with the DataSource by itself.We should be releasing a preview of this work soon.

    Scott Hunter
    PM, ASP.NET Team, Microsoft
  • Re: How to search grid results based on user provided values?

    10-07-2008, 7:30 AM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    Hi Scott,

     Thanks for the reply.  I have looked at Josh's stuff and it is real good but it generates one text field per column.  What I would like to have is one text field filter that would filter over multiple columns.

    For example, on a page to maintain various categories in my system...

    Each category has a NameEn, NameFr, DescriptionEn and DecriptionFr column.  I am only showing the NameEn and NameFr in the list page.  I would like to have one filter (text entry field) on the list page that would search across NameEn, NameFr, DescriptionEn and DescriptionFr at the same time.

    You guys are doing a great job.  This DD stuff is quite impresive.

    Regards,
    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-07-2008, 6:14 PM
    • Contributor
      5,854 point Contributor
    • ricka6
    • Member since 06-25-2008, 10:04 PM
    • Redmond
    • Posts 941
    • AspNetTeam
      Moderator

    jfaigan:
    What I would like to have is one text field filter that would filter over multiple columns.For example, on a page to maintain various categories in my system...

    Each category has a NameEn, NameFr, DescriptionEn and DecriptionFr column.  I am only showing the NameEn and NameFr in the list page.  I would like to have one filter (text entry field) on the list page that would search across NameEn, NameFr, DescriptionEn and DescriptionFr at the same time.

    You guys are doing a great job.  This DD stuff is quite impresive.

    Hey Joel,

    You're in luck. I'm working on that exact scenario right now. You will be able to search multiple columns from one filter. We hope to have a sample posted the end of this month.

    Rick -ASP.Net UE MVC FAQ   Rick on MVC & Dynamic Data   
  • Re: How to search grid results based on user provided values?

    10-07-2008, 7:00 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    Wow...I'm so happy I think i'm going to cry...   Big Smile  

    That is excllent news!  Please keep me posted.

    Have a great day.

    Regards,
    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-17-2008, 11:16 AM
    • Member
      102 point Member
    • jheyse
    • Member since 04-10-2008, 4:56 PM
    • Chicago
    • Posts 43

    Are you trying to search for only text or all values?  For example if you put a date into the text box shoudl it be able to convert and search DateTime columns?

    This is similar to the custom column defined here:

    http://blogs.catalystss.com/blogs/josh_heyse/archive/2008/05/23/a-richer-dynamicdatafilter-part-5-columncontains.aspx

  • Re: How to search grid results based on user provided values?

    10-17-2008, 9:48 PM
    • Member
      102 point Member
    • jheyse
    • Member since 04-10-2008, 4:56 PM
    • Chicago
    • Posts 43
  • Re: How to search grid results based on user provided values?

    10-18-2008, 12:55 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    jheyse:

    Are you trying to search for only text or all values?  For example if you put a date into the text box shoudl it be able to convert and search DateTime columns?

    This is similar to the custom column defined here:

    http://blogs.catalystss.com/blogs/josh_heyse/archive/2008/05/23/a-richer-dynamicdatafilter-part-5-columncontains.aspx

    Hadn't really thought about that...I guess that could be very interesting...if the "multi-filter" took into account the data type and tried to convert the user input...

    The "multi-filter" would only need to check against columns that subscribed to it...for example if I had a birthdate field I wouldn't want the created and modified date fields to be searched as well...that would affect the filter results.

    I wil check out your link!  Thanks for the input!

    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-18-2008, 1:00 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    jheyse:

    I just checked out the example and that looks pretty amazing!  I am going to try to implement it (hopefully today) and I will post feedback here.

    Once again, thank you very much for your help.

    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-18-2008, 7:14 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    Hey jheyse,

    I've been trying to implement your TableTextSeach filter control and I've copied over the code from your post but I am getting compile errors about missing references (for example it cannot find IDynamicDataSource).  Am I missing a reference?

    Have you added this component to CodePlex?

    Thanks a lot!

    Joel.

     --EDIT--

    Forget what I said...I was just missing a using stmt.

    Joel.

    --EDIT--

    Ok, almost have it compiling without errors...most recent error is on cols.Trim()...getting an error that System.Array does not support Trim()
    Am I missing a reference or using stmt?

    Also, where is your Columns attribute defined?  Which namespace?  I assume that this becomes metadata on the table partial class.

    Do you perhaps have a working example?

    Thanks,
    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-22-2008, 7:35 AM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    Hey jheyse,

    Have you had a chance to review this post?

    I removed the Trim() call from the code and everything compiles but without the attribute class it is only searching across all columns.  Do you have the code for your attribute class?  Will you be publishing a new version of your code soon?

    Regards,
    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-22-2008, 10:52 AM
    Answer
    • Member
      102 point Member
    • jheyse
    • Member since 04-10-2008, 4:56 PM
    • Chicago
    • Posts 43

    Hey Joel,

    Sorry for the late response.  My blog had some issues with the converting code into emotiocons.

    Below should be a version of the filter column that compiles.

     

    using System;
    using System.Collections;
    using System.Configuration;
    using System.Data;
    using System.Linq;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Xml.Linq;
    
    using Catalyst.Web.DynamicData;
    
    public partial class TableTextSearch : Catalyst.Web.DynamicData.FilterTemplateUserControlBase
    {
        public string Columns { get; set; }
     
        private MetaTable Table
        {
            get
            {
                IDynamicDataSource source = this.FindDataSourceControl();
                if (source != null)
                    return source.GetTable();
                return null;
            }
        }
     
        public override IEnumerable GetWhereParameters(System.Web.DynamicData.IDynamicDataSource dataSource)
        {
            OrExpressionParameter parameter = new OrExpressionParameter();
     
            string[] cols = null;
            if (!string.IsNullOrEmpty(Columns))
            {
                cols = Columns.Split(',');
                for (int i = 0; i < cols.Length; i++)
                    cols[i] = cols[i].Trim().ToUpper();
            }
     
            var columns = (from c in Table.Columns
                           where cols == null || cols.Length == 0 || cols.Contains(c.Name)
                           group c by c.TypeCode).ToDictionary(g => g.Key, g => g);
     
            foreach (var column in columns[TypeCode.String])
            {
                parameter.Parameters.Add(new LikeExpressionParameter()
                        {
                            Type = TypeCode.String,
                            Name = column.Name,
                            Value = TextBox1.Text,
                            Like = LikeExpressionParameter.LikeType.Contains
                        });
            }
            yield return parameter;
        }
     
        public override void LoadQueryStringParameters(System.Collections.Specialized.NameValueCollection parameters)
        {
            TextBox1.Text = parameters["TableTextSearch"];
        }
     
        public override System.Collections.Specialized.NameValueCollection SaveQueryStringParameters()
        {
            return new NameValueCollection() { { "TableTextSearch", TextBox1.Text } };
        }
     
        public override void Clear()
        {
            TextBox1.Text = string.Empty;
        }
    }
      



     

  • Re: How to search grid results based on user provided values?

    10-22-2008, 6:25 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    Hi jheye,

     Thanks for getting back to me.

    I was able to get your original code to compile but I had to remove

    //for (int i = 0; i < cols.Length; i++)
    // cols = cols.Trim().ToUpper();

    because Trim().ToUpper() are extensions to the array class that I do not have.  Did you create these extensions?

    Also, I do not have the attribute class for defining the metadata.  Do you have the code for the attribute?

    Please let me know if you don't know what I am talking about.

    Thanks for all of your help!

    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
  • Re: How to search grid results based on user provided values?

    10-22-2008, 7:30 PM
    • Member
      102 point Member
    • jheyse
    • Member since 04-10-2008, 4:56 PM
    • Chicago
    • Posts 43

    Joel,

    The in the code above cols is an array of strings.  The Trim() method should be being called on the index of cols at i.  cols[i] = cols[i].Trim().ToUpper(); If you just comment the code out you will have some adverse side effects.

    I'm not sure what you mean when you refer to the attribute for the metadata.  Can you please clarify.

    Josh

  • Re: How to search grid results based on user provided values?

    10-22-2008, 8:30 PM
    • Member
      32 point Member
    • jfaigan
    • Member since 12-05-2007, 4:12 PM
    • Posts 38

    jheyse:

    Joel,

    The in the code above cols is an array of strings.  The Trim() method should be being called on the index of cols at i.  cols[i] = cols[i].Trim().ToUpper(); If you just comment the code out you will have some adverse side effects.

    I'm not sure what you mean when you refer to the attribute for the metadata.  Can you please clarify.

    Josh

    Ok, just saw the problem...I did not have the array indexer...must have got lost when I did the original copy...I was trying to apply theTrim to the array which is why I was getting the missing extension error.

    As for the attribute...how do I specify on the partial class which columns should participate in this search.  You mentioned that if no columns are specified then all columns will be searched...but how do you specify the distinct set of columns to search?  What is the attribute to be used?

    Thanks a lot!

    Joel.

    Joel Faigan
    President
    Cardinal Point Software Inc.
Page 1 of 2 (20 items) 1 2 Next >