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

MultiSelection FilterTemplate

21 Answers 161 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Daní
Top achievements
Rank 1
Daní asked on 07 Oct 2010, 10:52 AM
Hi,

I'm using DataFilter in unbound mode. So each time a filter is added/removed/modified I'm reading the entire filter hierarchy anb build my own custom filtering system. I'm providing several filter templates, for example, one with a combobox where users can choose one item to filter. Now, I would like to provide a multiselection filter. That's instead of using a combobox, I'd lik to use a "CheckedListBox" to allow users to select more than one value (then I will expand all selections in an OR filter). The matter is on SimpleFilterViewModel class, it provides the property Value of type object, I'd like to set its value to a collection of selected options, but, as I could see in source code, the setter of this property is calling a private method that checks for type correctness of the provided value, so, if filter property is a string, I cannot set the value to a string collection. I'd like to know if it's possible to provide a public method DirtySetValue (for example) to avoid type checking.

thanks.

21 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 11 Oct 2010, 11:36 AM
Hello DanĂ­,

Unfortunately, that would not be possible. Even if we do it -- the data engine will not support it, so there is no point in doing it.

This *might* be possible when this feature is developed. You will be able to define an entirely custom UI for an entirely custom IFilterDescriptor. But it will be up to you to implement the IFilterDescriptor. It will be able to perform any kind of custom filtering logic, but I have to admit that implementing IFilterDescriptor is far from trivial.

If you think that the feature I have mentioned can help you achieve your goal, please vote for it in order to raise its priority.

All the best,
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
0
Daní
Top achievements
Rank 1
answered on 23 Nov 2010, 11:28 AM
Hello,

Still fighting for getting a MultiOption filter. I don't know if the CustomFilter is finally implemented in Q3 release. Is so, any demo would be apreciated. I was trying to do the MultiOption filter via extension methods, but I'm having some problems. May be someone can help me.

I've created a custom control, it's simply a button with a Popup that contains a "CheckedListBox". Each item in this CheckedListBox is one of the options for the Property being filtered. This custom controls is the DataTemplate content for the FilterTemplateSelector, so the control's DataContext is a SimpleFilterViewModel instance. Whenever user checks/unchekcs any item from the List, I'd like to set the SimpleFilterViewModel value with a list with all checked items. Of course, due SimpleFilterViewModel type checking when setting Value property, I can't do that, so I've done a SimpleFilterViewModel extension and I notify my ViewModel object using a command. But now, I'm facing a new matter, my ViewModel builds the filtering expression using the RadDataFilter's FilterDescriptors property, so I have no way to acces the SimpleFilterViewModel updated in the custom control. I've seen that SimpleFilterViewModel has a private (or protected) property called Descriptor (I supose is the FilterDescriptor). Is there any workaround to solve this? Reflection is not running so I cannot acces private/protected members in external assemblies.
0
Rossen Hristov
Telerik team
answered on 23 Nov 2010, 04:13 PM
Hi DanĂ­,

I understand what you are trying to achieve but until we develop the Custom filtering UI for custom filter descriptors feature it will be impossible to do this.

Unfortunately, we have not delivered it for the Q3 Release and I cannot provide a specific time-frame for this feature.

Please, accept our apologies.

Sincerely yours,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 23 Nov 2010, 04:18 PM
Hi Ross,

So, there is no way to retrieve the related FilterDescriptor from SimpleFilterViewModel and/or vicevers?
0
Daní
Top achievements
Rank 1
answered on 23 Nov 2010, 07:36 PM
Hi Ross

Meanwhile  Custom filtering UI for custom filter descriptors feature  is not implemented, may I ask to make the Descriptor property in SimpleFilterViewModel public?. I think that would be enough for me. My users are actively demanding this feature and I think I can achive it using class extensions.

Thanks.
0
Rossen Hristov
Telerik team
answered on 24 Nov 2010, 11:32 AM
Hi DanĂ­,

Before making such an important decision (you know that once something goes public there is no going back), can you explain with an example this use case:

Whenever user checks/unchekcs any item from the List, I'd like to set the SimpleFilterViewModel value with a list with all checked items.

I would like to know this, because I am almost sure that if you set a List of  values to be the Value of a FilterDescriptor then the data engine will not accept that at all, i.e. it does not support such complex expressions. So what you are trying to achieve might not be possible on the data layer level.

Can you give me a simple example about the FilterDescriptor's desired Member, Operator and Value in this use case.

I am looking forward to hearing from you.

Sincerely yours,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 24 Nov 2010, 11:59 AM

Hi Ross,

I'll try to explain the better I can what I want to do.

As I told you before, I have developped a custom control, called MultiOptionFilter. This controls contains a textblock and a button that causes a popup to be open; this popup contains a "CheckedListBox" that contains all the options for the property being filtered. This control is the DataTemplate's content used in the DataFilter.TemplateSelector whenever user choose "Equals" operator. So, this control receives as its DataContext a SimpleFilterViewModel instance; as this control its in the DataFilter visual tree, I can get the parent's DataFilter that has as DataContext my ViewModel instance. At this point, having my ViewModel instance and the SimpleFilterViewModel I can create a List with all the possible values for the property being filtered, this List is used in the CheckedListBox as its options.

My ViewModel class has a FilterDescriptors property. When DataFilter is loaded by first time it takes its DataContext (my ViewModel instance) and set its FilterDescriptors => MyViewModel.FilterDescriptors = DataFilter.FilterDescriptors, at this poitn, my ViewModel can listen for changes in FilterDescriptors and update its Filter expression.

In my first attempt, I made a SimpleFilterViewModel extension, the code is attached below:

public static class SimpleFilterViewModelExtensions
   {
       private static Dictionary<SimpleFilterViewModel, object> _values = new Dictionary<SimpleFilterViewModel, object>();
       public static void SetDirtyValue(this SimpleFilterViewModel filter, object value)
       {
           _values[filter] = value;
       }
       public static bool TryGetDirtyValue(this SimpleFilterViewModel filter, out object value)
       {
           return _values.TryGetValue(filter, out value);
       }
       public static void Release(this SimpleFilterViewModel filter)
       {
           _values.Remove(filter);
       }
   }

So, whenever user checks an item in the CheckedListBox I call SetDirty method. At this point, I had a problem, how to notify my ViewModel that a DirtyValue was inserted? The solution was to introduce a command to the control, when users checks an item, the command is executed.

The final problem is that my ViewModel has the FilterDescriptors collection, so it has acces to the FilterDescriptor instances but it has no way to access the SimpleFilterViewModel, so it cannot read the DirtyValue defined in the extension.

As I saw that SimpleFilterViewModel has a private Descriptor property of type FIlterDescriptor, I supose this Descriptor is the same that my ViewModel can access, so I think I can remove my SimpleFilterViewModelExtensions class and create the same class for the FilterDescriptor. In my MultiOption control, having SimpleFilterViewModel.Descriptor as a public property, I can set its DirtyValue and in my ViewModel class, I'll be able to call DirtyRead for the FilterDescriptor.

Waiting for you opinion
0
Rossen Hristov
Telerik team
answered on 24 Nov 2010, 12:30 PM
Hi DanĂ­,

I kind of get it, even though not completely. If I manage to get it completely I might be able to think of a workaround since this same FilterDescitptor could be found in the collection called FilterDescriptors.

You are right for the fact that each SimpleFilterViewModel wraps a FilterDescirptor object which is one of the objects in the FilterDescitptors collection. When you click a plus sign, the SimpleFilterModel is created, it creates a new instance of the FilterDescriptors class and adds it to its parent CompositeFilterDescriptor based on the level on which it is. But for the sake of simplicity, let's keep the RadDataFilter flat.

But what Value do you want to assign to this FilterDescriptor. Can the user check many things from this CheckedListBox or only one?

Let's give an example. You have a property called Continent. The user selects the Equal operator and he is presented with the options: Europe, America, Africa, Asia, etc. He selects Asia and Europe. What FilterDesciptors should be present in the collection and what values should they have?

By the way, if you open a separate support ticket and you send me a small sample with all these things, I can take my time, examine them see what you are talking about. Maybe this will save us a lot of time. I am sure we will be able to think of a solution.

I will be waiting for your reply. And please, tell me about FilterDescriptor.Value -- what do you want it to be?

Kind regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 24 Nov 2010, 12:40 PM
Hi Ross,

I'll try to do a simple demo solution. About FilterDescriptor.Value, it will remain to Unset all time. Having the FilterDescriptorExtension class, whenever user checks/uncheks any item in the CheckedListBox, the MultiOptionFilter control creates a collection with the checked items, call it CheckedItems, calls SimpleFilterViewModel.Descriptor.SetDirtyValue(CheckedItems) and then executes the Command to notify the ViewModel that the filter has changed. The ViewModels walks all the FilterDescriptors collection, and when it finds a FilterDescriptor with "Equals" operator it calls FilterOperator.TryGetDirtyValue to get the the checked items list set previously by the MultiOptionFilter control, so it can build a filtering expression with an Or of all checked items.

So the FilterDescriptorExtension class, with the SetDirtyValue and TryGetDityValue methods, serves to bypass the FilterDescriptor.Value property and avoid the type correctness check it makes each time Value property is set.

Hope this clarify.
0
Accepted
Rossen Hristov
Telerik team
answered on 24 Nov 2010, 01:25 PM
Hello DanĂ­,

Finally I got it. You are simply using the FilterDescriptor instance as a "mule" to carry your specific data to your end point and then assemble it and build the expression.

I will make it public and it should take effect with the Latest Internal Build coming out this Friday. If you can't wait until then, I will send you a manually prepared build. In case you want a custom build, please open a separate support ticket, since I can't attach it here in the public forum.

This idea is brilliant by the way! I would have never thought of that.

Kind regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 24 Nov 2010, 02:45 PM
Exactly Ross,

My apologizes for my bad explanations and my poor english. Thank you very much, I can wait until friday.

I will upload an example to share with other users when all runs fine.
0
Daní
Top achievements
Rank 1
answered on 25 Nov 2010, 11:25 AM
Hi Ross,

I don't know what Custom filtering UI for custom filter descriptors feature is expected to do. I think that a simple solution might offer users the possibility to implement any custom filtering, at least in unbound mode. Based on my purpose, where I'm using FilterDescriptor to carry out custom data to the endpoint when the custom filter expression is built, may suggest a bit deeper changes in FilterDescriptor and SimpleFilterViewModel?

As you know, to reach my purpose, I have to implement a FilterDescriptorExtension class (that holds my custom data), I also need to define an interface with an ICommand property that my ViewModel class has to implement to make possible my custom control notifies it whenever user checks/unchecks an option and finally you have had to make the SimpleFilterViewModel's Descriptor property public. That supose some confusing stuff to get all workin fine... What I purpose is implementing the DirtyValue funcionality built in the DataFilter control. Of course, you know much better the internal stuff, but I think with some few changes we'll have all the tools to built any custom filtering implementation. So, adding a DirtyValue property (object typed, with no type correctness check) to FilterDescriptor and SimpleFilterViewModel and raising the FilterChanged event whenevers it changes will be enough and will safe users to write some tedious code.

Thanks.

DanĂ­
0
Rossen Hristov
Telerik team
answered on 25 Nov 2010, 12:56 PM
Hello DanĂ­,

I have just checked this in:

/// <summary>
/// Gets the underlying FilterDescriptor.
/// </summary>
/// <value>The underlying FilterDescriptor.</value>
[Browsable(false)]
[EditorBrowsable(EditorBrowsableState.Never)]
public FilterDescriptor Descriptor
{
    get
    {
        return this.descriptor;
    }
}

It will not show up in the intellisense, so don't tell anyone :) :)

Kind regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 25 Nov 2010, 01:01 PM
Thank you so much Ross. You'll make happy my end users in the next release
0
Rossen Hristov
Telerik team
answered on 25 Nov 2010, 01:05 PM
Hi DanĂ­,

You are welcome. Your goal is to make your customers happy and my goal is to make you happy.

Regards,
Ross
the Telerik team
Browse the videos here>> to help you get started with RadControls for Silverlight
0
Daní
Top achievements
Rank 1
answered on 24 Jan 2011, 01:25 PM
Hi Ross,

I uploaded a demo project to show how achieve advanced custom filtering with this approcah at Code Library butI forgot to attach the demo solution. Now, the thread does not appear int the code library, I supose you need to check it before publising, How can I attach the missing demo?

Thanks.
0
Veselin Vasilev
Telerik team
answered on 27 Jan 2011, 04:27 PM
Hi DanĂ­,

You can upload the project here (login in our web site and edit your response to attach the files).

Regards,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Veselin Vasilev
Telerik team
answered on 02 Feb 2011, 03:56 PM
Hello DanĂ­,

The code library is moved to the DataFilter category and can be found here.

Your points have been updated.

Kind regards,
Veselin Vasilev
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
RoadWarrior
Top achievements
Rank 1
answered on 22 Jun 2011, 07:08 PM
I am trying to do the same thing, but still see a couple of issues when running the posted solution:

  • When the operator change, your displayed value is reset to "No Items Selected"
  • Similarly, when a FilterDescriptor is nested, it will completely loose the selected value list.

Any ideas on how to fix these problems?
0
Daní
Top achievements
Rank 1
answered on 22 Jun 2011, 09:58 PM
Hi RoadWarrior,

I've just uploaded a new version on code library. Just download the second file (.rar) here.

First issue is solved.

About second issue, I do not really understand what do you mean. You must think than when nesting, the current filter is destroyed and it creates two new filter items, so there's no way to keep selection in any of th new filter items.

I've uploaded the version I'm using on my application release version, so you'll may see that several features are added to solution.
0
RoadWarrior
Top achievements
Rank 1
answered on 23 Jun 2011, 12:23 AM
Thanks for the update.  Will check it out.

Regarding the second issue, this is in fact the behavior exhibited by the default editors.  Try nesting an TextBox-based editor with a value set, and you will see that the 1st Filter will preserve the value, and second one is blank.  

Tags
DataFilter
Asked by
Daní
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Daní
Top achievements
Rank 1
Veselin Vasilev
Telerik team
RoadWarrior
Top achievements
Rank 1
Share this question
or