How to implement non source use of datafilter

2 posts, 0 answers
  1. Paw
    Paw avatar
    8 posts
    Member since:
    Mar 2010

    Posted 23 Aug 2010 Link to this post

    Hi

    The following little example should illustrate my problem.

    I have three classes in my system:

    1. Class Person
      - Name
      - Age.

    2. Class Student : Person (Inherites from Person)
      - Grade

    3. Class Teacher : Person (Inherites from Person)
      - Wage level

    My system holds a complete list of Teachers and students like

      ObservableCollection<Person>

    I have different kinds of GUI controls (listview and radCarousel sofar) that binds to this collection. If I use the radFilterData component in source mode then I see only Name and Age in the field selector. I want to be able to see Name, Age, Grade, Wage level eventhough some of them only makes sence according a specific person type. I use ItemProperties and non source mode to archieve that.

    My problem is that I am a little bit confused how to do the rest. I have seen the Domain examples but doesn't guite get it. I assume I have to handle this event:

      radDataFilter.FilterDescriptors.CollectionChanged += this.OnRadDataFilterDescriptorsChanged;

    But how should I do that. I should also say that I have already implemented sorting and grouping using the

      CollectionViewSource.GetDefaultView

    Hopefully I will be able to have sorting, grouping and filtering working side by side. 

  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 24 Aug 2010 Link to this post

    Hi Paw,

    I am afraid that mixing Students and Teachers in the same list will complicate things enormously.

    We have an extension method called .Where that can filter an IQueryable based on a collection of FilterDescriptors, but you will not be able to use it if your collection is heterogeneous, because an exception will be raised if you try to filter on a property that is not a member of the base Person class.

    Your only option would be to attach to the two events of the FilterDescriptors collection:

    - CollectionChanged
    - ItemChanged

    In the event handler of these two events you will receive notification about what is changed -- either a descriptor was added/removed or a property of an existing descriptor was changed.

    From then on, you will have to devise a way to transfer this filtering information to your CollectionViewSource. Maybe you can use its Filter event to translate the information stored in RadDataFilter.FilterDescriptors to your CollectionViewSource.

    I hope this helps.

    Regards,
    Ross
    the Telerik team
    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 Public Issue Tracking system and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top