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

DataFilter sub-collections

4 Answers 115 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Jerome
Top achievements
Rank 1
Jerome asked on 22 Aug 2011, 09:01 PM
I'm wondering if anybody has done any work extending DataFilter to handle dealing with child collections in a complicated manner. For instance, I have an IParent interface, which has an IEnumerable<IChild> Children member. I'd like to be able to express visually:

from p in parents where p.Children.Any(i => i.Type == 1 && i.Foo = "Bar")

Basically, I want to select parents based on whether any children exists.

I have this notion that I could implement this entirely on my own... somehow. Perhaps a custom 3-part editor control for teh Children property, with a "any" operator... and a sub-RadDataFilter rendered in part-3.

That seems pretty kludgy though.

4 Answers, 1 is accepted

Sort by
0
Jerome
Top achievements
Rank 1
answered on 22 Aug 2011, 10:29 PM
Okay, I've figured out how to add a custom editor... but I haven't figured out how to modify the "operator" stuff. I'd really like to replace the Operator and Editor for a given property.
0
Rossen Hristov
Telerik team
answered on 23 Aug 2011, 06:28 AM
Hi Jerome,

I am afraid that RadDataFilter cannot handle the complex filter that you describe. It can only use simple FilterDescriptors which contain filtering information of the form Member-Operator-Value. The FilterDescriptor class only supports this kind of filtering expression, it cannot handle the p.Children.Any expression that you would like to filter on. Even if you were able to change the editor and operator, the data engine that sits below would fail, since it uses the FilterDescriptor class to describe a condition, and that class does not support arbitrary expressions such as the one you have.

The only workaround for your requirement that I can think of would be to create a new read-only boolean property that will return the result of "p.Children.Any(i => i.Type == 1 && i.Foo = "Bar")", name this property in some way, and then let RadDataFilter filter on that boolean property. I am afraid that there is no other way to achieve this.

Thank you for your understanding.

Greetings,
Ross
the Telerik team

Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

0
Jason
Top achievements
Rank 1
answered on 23 Sep 2011, 05:54 PM
Ross,

I have run into a similar situation where I would like to filter for a parent based on a value within a child. Is there any way to do this without hardcoding the values in the LINQ query? I am using VB so I can use a parameterized property like this:

Public ReadOnly Property HasMatchingChild(ByVal value As String) As Boolean
  Get
    Return Children.Any(Function(x) x.Property.Equals(value))
  End Get
End Property

In this case I could set the ItemPropertyDefinition's PropertyName to HasMatchingChild and it's PropertyType to Boolean. I would then set the DataTemplate to show a textbox to get the parameter to search by. What I can't figure out is how I would then use the textbox's value as the parameter for HasMatchingChild. Is this even possible?

Jason
0
Rossen Hristov
Telerik team
answered on 26 Sep 2011, 09:28 AM
Hi Jason,

I am afraid that currently a scenario like this one cannot be supported.

Best wishes,
Ross
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
DataFilter
Asked by
Jerome
Top achievements
Rank 1
Answers by
Jerome
Top achievements
Rank 1
Rossen Hristov
Telerik team
Jason
Top achievements
Rank 1
Share this question
or