Event trigger when FilteredSource is updated

5 posts, 0 answers
  1. Shawn
    Shawn avatar
    39 posts
    Member since:
    Jul 2012

    Posted 11 Oct 2011 Link to this post

    Is there currently a way to trigger an event when the FilteredSource has been updated by the DataFilter? Something like a CollectionChanged event or FilteredCompleted.

    Thanks,
    Shawn
  2. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 12 Oct 2011 Link to this post

    Hi Shawn,

    I suppose that you want to receive a notification each time when the the user has changed the filtering criteria and thus the items in the FilteredSource have changed.

    If that is correct, you can cast the FilteredSource property to INotifyCollectionChanged interface (it is one) and then listen for its CollectionChanged event. It will be fired each time the items inside it change.

    In case I have misunderstood the requirements, please let me know and tell me what is the exact behavior that you are after.

    Best wishes,
    Ross
    the Telerik team

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

  3. UI for WPF is Visual Studio 2017 Ready
  4. Shawn
    Shawn avatar
    39 posts
    Member since:
    Jul 2012

    Posted 12 Oct 2011 Link to this post

    Hi Ross, 

    Thanks for the response. I don't think I realized you could cast the Source to the INotifyCollectionChanged interface. Nice trick but it is not quite a perfect solution.

    I've implemented this in my scenario and it does work to a certain extent but there are two catches. 

    The first is the FilteredSource is null and cannot have the CollectionChanged event bound to it until after you bind the source. Not a big deal but something to be aware of.

    The second  is that every little click you make in the filtered control causes the event to be triggered (i.e. simply adding a new condition, selecting the parameters and then providing a value triggers the event three times) which can be painful if you have a large amount of data to be filtered or a complex post-filter operation. The NotifyCollectionChangedEventArgs returns null for both NewItems and OldItems so there is no easy way to tell if and what data has changed and comparing the source against the filtered seems inefficient. 

    Ideally it would be nice to have this event handled internally to the DataFilter and it provide a single event back to the user that only triggers after the data has completed being filtered. 

    Regards,
    Shawn
  5. Rossen Hristov
    Admin
    Rossen Hristov avatar
    2478 posts

    Posted 13 Oct 2011 Link to this post

    Hello Shawn,

    I have prepared a sample project that uses a completely different approach. 

    Basically, each time that something changes on the RadDataFilter.FilterDescriptors, it evaluates the new filtering expression and compares it with the last one that was cached. If they are different, this means that the filtering criteria in RadDataFilter has changed. The good thing here is that when you click the Property Name drop-down and then the FilterOperator drop-down, this will not cause redundant events because when a FilterDescriptor is Unset it does not take part in the building of the expression.

    To summarize, the Debug.WriteLine in the sample project will be hit if and only if the actual filtering expression of RadDataFilter has changed. You can use the debugger and see what kind of LINQ expressions we generate if you are interested in this kind of stuff. Simply watch the ToString() methods calls of the two expressions being compared and see what they return.

    I hope this helps.

    Regards,
    Ross
    the Telerik team

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

  6. Shawn
    Shawn avatar
    39 posts
    Member since:
    Jul 2012

    Posted 17 Oct 2011 Link to this post

    Hi Ross,

    Sorry for the delay in writing back. Your new solution works very nicely in my environment and the reduced triggers are very helpful. This would be a good example to include as a demo with the next release of the control.

    Thanks again for your support and providing a working solution.

    Regards,
    Shawn
Back to Top
UI for WPF is Visual Studio 2017 Ready