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

Filter GridView Column

3 Answers 44 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 10 Jul 2014, 06:56 PM
Hi,

I have a problem with the GridViews's standard filter. I use the filter setting "contains".
Here is the entire search string: "Pinset Borussia, Wappen, Figur"

If I type in Pinset Borussia the item is found. 
If I type in Pinset Wappen, the item cannot be found, although I used the filter option "contains".

Do you have a soloution to this problem?

Thank you and sorry for my English :).

Pierre

3 Answers, 1 is accepted

Sort by
0
Pierre
Top achievements
Rank 1
answered on 11 Jul 2014, 10:45 AM
Sorry, I don't know if you could understand my problem.
For better understanding I created two screenshot to show you this example.

What can I do that the filter in Example2 find the Item?

Thank you.

Pierre
0
George
Telerik team
answered on 15 Jul 2014, 11:32 AM
Hi Pierre,

Thank you for writing.

When filtering and the filter is "Contains" the rows are filtered only by the value in the textbox, they are not filtered by each word. Which means that the behavior you are getting is expected. You can, however implement such functionality by yourself by using CompositeFilterDescriptors. You can subscribe to the FilterChanged event of RadGridView and split the values so that you can create a separate descriptor for each word:
private void Grid_FilterChanged(object sender, GridViewCollectionChangedEventArgs e)
{
    if (e.NewItems == null || e.NewItems.Count == 0 || e.NewItems[0] is CompositeFilterDescriptor)
    {
        return;
    }
 
    FilterDescriptor desc = e.NewItems[0] as FilterDescriptor;
    if (desc != null && desc.Operator == FilterOperator.Contains)
    {
        this.Grid.FilterDescriptors.Clear();
        string[] values = (desc.Value as string).Split();
        CompositeFilterDescriptor compositeDescriptor = new CompositeFilterDescriptor();
        compositeDescriptor.LogicalOperator = FilterLogicalOperator.Or;
        for (int i = 0; i < values.Length; i++)
        {
            FilterDescriptor newDescriptor = new FilterDescriptor(desc.PropertyName, desc.Operator, values[i]);
            compositeDescriptor.FilterDescriptors.Add(newDescriptor);
        }
 
        this.Grid.FilterDescriptors.Add(compositeDescriptor);
    }
}

Feel free to modify this example according to your needs.

I hope this helps.

Regards,
George
Telerik
 
Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
 
0
Pierre
Top achievements
Rank 1
answered on 15 Jul 2014, 06:03 PM
Hi George,

thank you! Your answer works fine for me. 
In my situation. I only changed a small detail. I changed the operator Or to And.

compositeDescriptor.LogicalOperator = FilterLogicalOperator.And;

Great support.

Regards
Pierre
Tags
GridView
Asked by
Pierre
Top achievements
Rank 1
Answers by
Pierre
Top achievements
Rank 1
George
Telerik team
Share this question
or