RadControls version 2010 Q3 SP1 |
|
.NET version |
|
Visual Studio version 2010 |
|
programming language |
|
browser support |
all browsers supported by RadControls
|
PROJECT DESCRIPTION
My users was complaining the had to concatenate many OR filters of the same property to perform a multiselection filter. They wanted to be able to select several values in an only filter.
I decided to implement this feature, so I developped a custom control, MultiOptionFilter that I would use in conjunction with FilterTemplateEditorSlector. Whenever a FilterOperator was set to "IsEqualsTo" or "IsNotEqualsTo" I would show my custom control with a multi selection list. User might choice several options and it would be translated to an OR fitler with all selected values. But I found a big problem:
The MultiOptionFilter received as DataContext a SimpleFilterViewModel instance. SimpleFilterViewModel is a sort of wrapper of FilterDescriptio. It declares a Value (object) property that allows developper set the filter value. Whenever SimpleFilterViewModel.Value changes an event is raised to allow update the filter. The issue is that despite Value is object typed, SimpleFilterViewModel perfomrs a tyoe correctness check whenever you set this property. As my control allows multi selection, I need to set SimpleFilterViewModel to a collection and the type correctness check does not allow it. SimpleFilterViewModel keeps a reference of the inner FilterDescriptor, but it was'nt public. I thought if SimpleFilterViewModel.FilterDescriptor was public, I could solve this issue using type extensions. I contacted Telerik team in this forum thread
MultiSelection Filter thread and thanks to Ross I coulf get FilterDescriptor property public. Now I worte the next extension class for the FilterDescriptor type:
With these extesions, I could bypass the type correctness check performed by SimpleFilterViewModel in Value's property. That was great, but i needed to notify filter changes to update the filter result. So I created an interface that my ViewModel classes should to implement to use the MultiOptionFilter control.
This interfaces has two properties. Source allows MultiOptionFilter control to get all the avaialable options. MultiOptionFilterChangedCommand allow MultiOptionFilter control notifies the inner view model that the selected options have changed.
I'm attaching a demo project with an example.
As you can see, this approch can be usefull for any advanced filter scenario you can imagine