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

Event trigger when FilteredSource is updated

4 Answers 122 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 11 Oct 2011, 05:12 PM
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

4 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 12 Oct 2011, 09:58 AM
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 >>

0
David
Top achievements
Rank 1
answered on 12 Oct 2011, 04:34 PM
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
0
Rossen Hristov
Telerik team
answered on 13 Oct 2011, 09:27 AM
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 >>

0
David
Top achievements
Rank 1
answered on 17 Oct 2011, 03:31 PM
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
Tags
DataFilter
Asked by
David
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
David
Top achievements
Rank 1
Share this question
or