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
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

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.

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?
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

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"

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.
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