DataFilter sub-collections

5 posts, 0 answers
  1. Jerome
    Jerome avatar
    87 posts
    Member since:
    Aug 2010

    Posted 22 Aug 2011 Link to this post

    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.
  2. Jerome
    Jerome avatar
    87 posts
    Member since:
    Aug 2010

    Posted 22 Aug 2011 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 23 Aug 2011 Link to this post

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

  5. Jason
    Jason avatar
    21 posts
    Member since:
    Nov 2010

    Posted 23 Sep 2011 Link to this post

    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
  6. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 26 Sep 2011 Link to this post

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

Back to Top
UI for WPF is Visual Studio 2017 Ready