This is a migrated thread and some comments may be shown as answers.

Filter is case sensitive, how do i change that?

12 Answers 1194 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jingying Wu
Top achievements
Rank 1
Jingying Wu asked on 30 Jul 2009, 08:54 PM
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

12 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 31 Jul 2009, 07:25 AM
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.
0
Saranya Parameswaran
Top achievements
Rank 1
answered on 24 Aug 2009, 12:39 PM
In the demo site the filtering is case sensitive. Can you please tell how to make it case insensitive.
0
Stuart
Top achievements
Rank 1
answered on 24 Aug 2009, 06:19 PM
Based on my investigations, it appears that filtering is case-sensitive in the "Is equal to" case, but not in "Starts with" or "Contains".
0
Kiran Guru
Top achievements
Rank 1
answered on 25 Aug 2009, 04:00 AM
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.
0
Rossen Hristov
Telerik team
answered on 27 Aug 2009, 07:54 AM
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.
0
Kiran Guru
Top achievements
Rank 1
answered on 27 Aug 2009, 10:47 AM
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?
0
Rossen Hristov
Telerik team
answered on 27 Aug 2009, 02:05 PM
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.
0
Thomas LEBRUN
Top achievements
Rank 1
answered on 19 Nov 2009, 12:46 PM
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 !
0
Rossen Hristov
Telerik team
answered on 20 Nov 2009, 01:08 PM
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.
0
Thomas LEBRUN
Top achievements
Rank 1
answered on 20 Nov 2009, 01:12 PM
Hi Ross,

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


Thanks !
0
nitish kumar
Top achievements
Rank 1
answered on 29 Dec 2009, 01:01 PM
This will work fine .
Do it on pageload :

RadGrid1.GroupingSettings.CaseSensitive = false;
0
Vlad
Telerik team
answered on 29 Dec 2009, 01:05 PM
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.
Tags
GridView
Asked by
Jingying Wu
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Saranya Parameswaran
Top achievements
Rank 1
Stuart
Top achievements
Rank 1
Kiran Guru
Top achievements
Rank 1
Rossen Hristov
Telerik team
Thomas LEBRUN
Top achievements
Rank 1
nitish kumar
Top achievements
Rank 1
Share this question
or