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

How to filter item's of the complex type?

1 Answer 63 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
dmitriy
Top achievements
Rank 1
dmitriy asked on 22 Jul 2015, 04:43 PM
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.

1 Answer, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 24 Jul 2015, 10:48 AM
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
Tags
DataFilter
Asked by
dmitriy
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Share this question
or