How to filter item's of the complex type?

2 posts, 0 answers
  1. dmitriy
    dmitriy avatar
    1 posts
    Member since:
    Jun 2014

    Posted 22 Jul 2015 Link to this post

    Hi!

    Is there a way to filter item's of the complex type in RadDataFilter?

    I know that fIlter works fine with simple entity classes like that:
    public enum MyEnum {A, B, C};
     
    public class ClassA
    {
        public string Name { get; set; }
        public int Count { get; set; }
        public MyEnum Type { get ;set; }
    }

    So I can request from a database some filtered data like that:
    var filters = new CompositeFilterDescriptorCollection();
    filters.AddRange(MyRadDataFilter.FilterDescriptors);
    filters.LogicalOperator = MyRadDataFilter.LogicalOperator;
     
    using (var context = new DbContext())
    {
        var result = context.Set<ClassA>().Where(filters);
        var data = result as  IEnumerable<ClassA>;
        return data.ToList();
    }

    And it returns me the data that matches my filter. For example, all ClassA items, where Count > 5.

    But I can't find out a way to do that with complex types. Here is one example:
    public class AddressClass
    {
        public string Country { get; set; }
        public string City { get; set; }
    }
     
    public enum GenderEnum { Male, Female };
     
    public class Person
    {
        public string Name { get; set; }
        public int Age { get; set; }
        public GenderEnum Gender { get; set; }
    }
     
    public class Doc
    {
        public DateTime Date { get; set; }
        public string Content { get; set; }
        public AddressClass Address { get; set; }
        public List<Person> Persons { get; set; }
    }

    So I have to load Doc's that mathes some filter like that : 
    All docs, where Address.City is NewYork
    or
        All docs in which there is a person older than 22 years.
    And so I need to give users the ability to set the conditions in the filter.

    How could I do?

    I would be glad to get a working example project.
    Hope to hear from you soon.
    Thanks.

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 24 Jul 2015 Link to this post

    Hi Dmitriy,

    I have prepared a demo application with custom editors for your convenience. Please check the editor for "Captain" property, as it demonstrates how an object can be filtered by a property of another one.

    I hope this helps.


    Regards,
    Stefan X1
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top