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

Custom filter for selecting values and matching from a list from each item in table

7 Answers 279 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Mark
Top achievements
Rank 1
Mark asked on 14 Jun 2017, 09:49 PM

I have a list of objects loaded into a RadGridView where the objects have a property that is a List<string>. This list is pulled from a list of possible values. 

 

class myTableItem{
    public int itemID {get;set;}
    public string name {get;set;}
    public List<string> tagList {get;set;}
}

 

What I would like to do is create a filter that displays a checkbox list of all possible tag values, and any item in the table whose tagList contains any of the values selected in filter will get displayed.

 

How would I do this? Is this something I need to create a custom filter for?

7 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 19 Jun 2017, 12:42 PM
Hi Mark,

This requirement can be satisfied by utilizing a custom FilterDescriptor and a custom column. The approach is demonstrated in the Filtering Collection Properties SDK Example. Can you please check it out? It can be reviewed through the SDK Samples Browser.

Hopefully, it helps.

Best Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Mark
Top achievements
Rank 1
answered on 19 Jun 2017, 01:18 PM

I've actually already been able to get this effect. 

To take that example, I'd like the filter box to contain a checkbox list of all the days of the week (which can be fed in from a separate source), and to be able to select multiple days. I'm not sure how to get that kind of result.

0
Mark
Top achievements
Rank 1
answered on 20 Jun 2017, 04:57 PM

From what I can tell, even when creating a custom filter control, the actual filtering mechanism has to be built out of the operators that are provided by Telerik, and it looks like they only deal with individual values.

Is what i'm asking for even possible?

0
Stefan
Telerik team
answered on 22 Jun 2017, 12:33 PM
Hi Mark,

Indeed, in order to filter the control, you need to manipulate its FilterDescriptors collection. As to your inquiry, a possible solution would be to utilize the CompositeFilterDescriptor object and set its LogicalOperator to OR, thus, generate a filtering criteria with multiple values. You can take a look at the Programmatic Filtering topic for more information.

Best Regards,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Mark
Top achievements
Rank 1
answered on 22 Jun 2017, 04:43 PM

With the Filtering Collection Properties example you linked to earlier, I noticed that not only do you have to type in the entire string, but it's also case sensitive. I have been trying to alter the logic to no success.

 

I created this extension method that I want to use in place of .Contains in that example project

public static class ext {
    public static bool AnyContains(this IEnumerable<object> source, string value) {
        return source.Any(s => s.ToString().ToLower().Contains(value.ToLower()));
    }
}

 

But I get the error "The type initializer for 'FilteringCollectionProperties.CollectionPropertyColumnFilterDescriptor' threw an exception."

with an InnerException of "Operation is not valid due to the current state of the object"

0
Mark
Top achievements
Rank 1
answered on 22 Jun 2017, 07:31 PM

Never mind. I figured it out. I went to Microsoft's source code for the LINQ functions and used them as a model, and came up with this.

public static class ext {
    public static bool AnyContains<TSource>(this IEnumerable<TSource> source, TSource value) {
        ICollection<TSource> collection = source as ICollection<TSource>;
        if (collection != null) return collection.Contains(value);
        return AnyContains<TSource>(source, value, null);
    }
 
    public static bool AnyContains<TSource>(this IEnumerable<TSource> source, TSource value, IEqualityComparer<TSource> comparer) {
        if (comparer == null) comparer = EqualityComparer<TSource>.Default;
        if (source == null) throw new ArgumentNullException("source");
 
        return source.Any(s => s.ToString().ToLower().Contains(value.ToString().ToLower())); ;
    }
 
}

 

And now it works. I'd still like to be able to able to have a checkbox list instead of typing them in, but I'll continue to work on it.

0
Stefan
Telerik team
answered on 27 Jun 2017, 11:22 AM
Hi Mark,

I am happy that you have managed to find a solution that meets your requirements.

In case you need any other assistance with our components, feel free to contact us again.

All the best,
Stefan X1
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Mark
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Mark
Top achievements
Rank 1
Share this question
or