Filter is case sensitive, how do i change that?

13 posts, 0 answers
  1. Jingying Wu
    Jingying Wu avatar
    22 posts
    Member since:
    Jul 2009

    Posted 30 Jul 2009 Link to this post

    How do i make the filter to be not case sensitive?
    Right now, the filtering is case sensitive and does not really meet our purpose
  2. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 Jul 2009 Link to this post

    Hi,

    By default the grid filtering is not case sensitive - you can check this demo for more info:
    http://demos.telerik.com/silverlight/#GridView/Search 

    Best wishes,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Saranya Parameswaran
    Saranya Parameswaran avatar
    2 posts
    Member since:
    Aug 2009

    Posted 24 Aug 2009 Link to this post

    In the demo site the filtering is case sensitive. Can you please tell how to make it case insensitive.
  5. Stuart
    Stuart avatar
    12 posts
    Member since:
    Feb 2009

    Posted 24 Aug 2009 Link to this post

    Based on my investigations, it appears that filtering is case-sensitive in the "Is equal to" case, but not in "Starts with" or "Contains".
  6. Kiran Guru
    Kiran Guru avatar
    3 posts
    Member since:
    Aug 2009

    Posted 24 Aug 2009 Link to this post

    Can we make IsEqualTo also use case in-sensitive matching? Also is it possible for the filter to Trim the value that is entered before applying it. For example if for the first name column the filter value is applied as "   Jack   ", then trim the value to "Jack" before applying it.
  7. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Aug 2009 Link to this post

    Hello Kiran Guru,

    We cannot insert such custom logic and make it the default. What if other users would like the space to have meaning and not be trimmed. If someone want to filter by "Jack" then he will have to enter "Jack" and not "  Jack  ".

    Nevertheless, we will try to invent a way to make this customizable in the future so that every developer will be able to configure the grid according to his preferences.

    Kind regards,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  8. Kiran Guru
    Kiran Guru avatar
    3 posts
    Member since:
    Aug 2009

    Posted 27 Aug 2009 Link to this post

    Trimming is fine, I found a fix for that. More importantly I want to make filtering case insensitive. Is there a way to configure this?
  9. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 27 Aug 2009 Link to this post

    Hello Kiran Guru,

    There is a way, but it is overly complex and may not work in some cases. Here it is if you want to examine and improve it:

    using System; 
    using System.Collections.Generic; 
    using System.Linq.Expressions; 
    using System.Reflection; 
    using System.Windows.Controls; 
    using Telerik.Windows.Controls.GridView; 
    using Telerik.Windows.Data; 
     
    namespace TicketID_231616_CaseInsensitiveFiltering 
        public partial class MainPage : UserControl 
        { 
            public MainPage() 
            { 
                this.InitializeComponent(); 
     
                this.playersGrid.ItemsSource = Club.GetPlayers(); 
                this.playersGrid.Filtering += this.OnFiltering; 
            } 
     
            private void OnFiltering(object sender, GridViewFilteringEventArgs e) 
            { 
                var newFilters = new List<IFilterDescriptor>(); 
                foreach (FilterDescriptor filterDescriptor in e.AddedDescriptors) 
                { 
                    var newFilter = new CaseInsensitiveFilterDescriptor(); 
                    newFilter.Member = filterDescriptor.Member; 
                    newFilter.Operator = filterDescriptor.Operator; 
                    newFilter.Value = filterDescriptor.Value; 
                    newFilters.Add(newFilter); 
                    break
                } 
     
                if (newFilters.Count > 0) 
                { 
                    e.AddedDescriptors.Clear(); 
                    this.playersGrid.FilterDescriptors.Add(newFilters[0]); 
                } 
     
                if (e.RemovedDescriptors.Count > 0) 
                { 
                    FilterDescriptor toRemove = null
                    foreach (IFilterDescriptor fd in this.playersGrid.FilterDescriptors) 
                    { 
                        if (fd is FilterDescriptor) 
                        { 
                            if (((FilterDescriptor) fd).Member == e.RemovedDescriptors[0].Member) 
                            { 
                                toRemove = (FilterDescriptor) fd; 
                                break
                            } 
                        } 
                    } 
     
                    this.playersGrid.FilterDescriptors.Remove(toRemove); 
                } 
            } 
        } 
     
        public class CaseInsensitiveFilterDescriptor : FilterDescriptor 
        { 
            protected override Expression CreateFilterExpression(ParameterExpression instance) 
            { 
                if (base.Operator == FilterOperator.IsEqualTo) 
                { 
                    MethodInfo toLowerMethod = typeof (string).GetMethod("ToLower"new Type[0]); 
                    MemberExpression member = Expression.Property(instance, base.Member); 
                    MethodCallExpression toLower = Expression.Call(member, toLowerMethod); 
                    LambdaExpression val = Expression.Lambda(toLower, instance); 
                    return Expression.Equal(toLower, Expression.Constant(base.Value.ToString().ToLower())); 
                } 
     
                return base.CreateFilterExpression(instance); 
            } 
        } 

    I have attached the project.

    Greetings,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  10. Thomas LEBRUN
    Thomas LEBRUN avatar
    66 posts
    Member since:
    Sep 2009

    Posted 19 Nov 2009 Link to this post

    Using the new version, is there a way to di this correctly ? indeed, each row of my grid is filled with an array of object (object[]) and thus, this tecnique is not working (or not properly)....

    Thanks !
  11. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 20 Nov 2009 Link to this post

    Hi Thomas LEBRUN,

    With the Q3 release we have obsoleted the AddedDescriptors and RemovedDescriptors properties and replaced the with the Added and Removed properties. The new properties are IEnumerable which means that they cannot be modified, i.e. they are for reading purposes only.

    With the same release however, we have introduced a new feature called Custom Filtering Controls. With it you can create any control with any custom logic and use it for filtering. Here is an example of two such custom filtering controls.

    So in your case you should create a custom filtering control like shown in the examples and use the CaseInsensitiveFilterDescriptor class (from this thread) to add / remove filters to the grid.

    By the way, I am currently in the process of writing a step-by-step tutorial on creating custom filtering controls. I will explain the whole process in great detail. The tutorial will also contain a fully-functional sample control along with the source code. Once I am ready with my article I will publish it on my blog. I hope that it will be available early next week.

    Best wishes,
    Ross
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  12. Thomas LEBRUN
    Thomas LEBRUN avatar
    66 posts
    Member since:
    Sep 2009

    Posted 20 Nov 2009 Link to this post

    Hi Ross,

    I'll keep an eye on your blog and I hope your post will be able to help me.


    Thanks !
  13. nitish kumar
    nitish kumar avatar
    3 posts
    Member since:
    Oct 2009

    Posted 29 Dec 2009 Link to this post

    This will work fine .
    Do it on pageload :

    RadGrid1.GroupingSettings.CaseSensitive = false;
  14. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 29 Dec 2009 Link to this post

    Hello nitish kumar,

    This is related to our ASP.NET AJAX grid - not to our Silverlight grid.

    Kind regards,
    Vlad
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top
DevCraft banner