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

Custom filter with 2 controls

6 Answers 93 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
Massimo
Top achievements
Rank 1
Massimo asked on 21 Apr 2015, 02:29 PM

I'm implementing a quite complex filter definition. I have to add a custom filter with 2 controls in it

Starting from this sample http://demos.telerik.com/silverlight/#DataFilter/CustomEditors

The class I'm using to save the values is this:

    public class DeltaTime
    {
        public TimeSpan Start { get; set; }
        public TimeSpan End { get; set; }
    }

And the xaml template is:

                    <DataTemplate x:Key="DeltaTimeTemplate">
                        <StackPanel Orientation="Horizontal" DataContext="{Binding Value, Mode=OneWay}">
                            <telerik:RadTimePicker SelectedValue="{Binding Start, Mode=TwoWay, FallbackValue={x:Null}}" DateTimeWatermarkContent="Start" />
                            <telerik:RadTimePicker SelectedValue="{Binding End, Mode=TwoWay, FallbackValue={x:Null}}" DateTimeWatermarkContent="End"  />
                        </StackPanel>
                    </DataTemplate>

It seems working, or at least the controls is displayed correctly. But, when I'm passing all filters, this filter value is <Unset>

6 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 22 Apr 2015, 02:43 PM
Hi Massimo,

If you haven't bound the custom editor to your view model properties, as shown  in the referred example, this would be an expected behavior.

You will need to subscribe to the EditorCreated event of RadDataFilter and data-bind the editor you have defined within the event handler. Since you have added two controls within a StackPanel, you can access them as in the code snippet below:
var timePickers = e.Editor.ChildrenOfType<RadTimePicker>().ToList();
if (timePickers != null)
{
    RadTimePicker startPicker = timePickers[0];
    RadTimePicker endPicker = timePickers[1];
}

I hope this makes sense.

Best Regards,
Stefan
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Massimo
Top achievements
Rank 1
answered on 28 Apr 2015, 06:36 PM

Ok, I really can't figure out.
I tried almost all kind of Bindings ( and also custom UserControls and other stuff) can you help me with this?
Here a simple project with my configuration: http://devfarm.it/~temp/TelerikWpfApp1.zip

0
Stefan
Telerik team
answered on 01 May 2015, 03:28 PM
Hello Massimo,

The filter descriptors are unset due to the fact that you are passing an object of custom data type. Since RadDataFilter is a data-bound control, it does not "know" what editor to create behind the scenes. You can check the Filter a Custom Type article for further reference. Please note, that this article is from our documentation on RadGridView, but the concept is basically the same.

As for defining two controls in one filter definition, after further investigation it seems that this would not be possible, as RadDataFilter's data engine does not support multiple values for its editor. Since filtering is a data operation, RadDataFilter builds and executes a LINQ query over the source collection using Where clause, therefore it can have only one editor value.The proper way to filter data in such scenario would be to simply add one more filtering criteria. Please excuse me for misleading you.

Best Regards,
Stefan
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Thomas
Top achievements
Rank 1
answered on 14 Oct 2016, 01:27 PM

Hello,

 

I was wondering if there are any exceptions to being unable to use two controls in one filter definition. For instance, I am trying to filter based on a ulong of bytes. It would be more user friendly if I could use two controls, have the user enter a numeric value as well as a unit value in a combo box (say, MB), and then I'd take those two values and convert them to bytes and filter on a single value. Basically what I want is a way to represent a single value across two controls.

 

I'd also like to be able to do this with DateTimes, so that a user can select a date on the calendar but also enter a time of day in a combo box. Again, I'd only filter on one DateTime value, it's just that it is represented across two controls.

 

Is there any way to accomplish this?

0
Stefan
Telerik team
answered on 19 Oct 2016, 10:49 AM
Hi Thomas,

As already mentioned in my previous reply, the filtering engine is highly dependent on the internally generated LINQ query. By-design the control is not meant to handle multiple editors for a single query. Modifying it so that such requirement is satisfied would require major modifications of the filtering engine, to which we cannot commit ourselves to. I am, however, researching whether a possible solution can be implemented through the existing API of the control. I will write back as soon as I have an update on my findings.

Best Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Stefan
Telerik team
answered on 25 Oct 2016, 10:30 AM
Hello Thomas,

Thank you for your patience.

I investigated all possibilities for applying such customization. The main obstacle for its implementation is the fact that when a custom editor is used, the DataContext of the predefined DataTemplate provides a single Value property that the control uses for processing the filtering operation. There can be multiple editors defined within the DataTemplate, but they will all be bound to the same aforementioned property, thus it would not make any sense at all. With this in mind, under the hood the engine will always build a LINQ query with a Where clause over the Value property only. I am afraid, that modifying this mechanism is something that we cannot commit ourselves to.

Best Regards,
Stefan X1
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
Tags
DataFilter
Asked by
Massimo
Top achievements
Rank 1
Answers by
Stefan
Telerik team
Massimo
Top achievements
Rank 1
Thomas
Top achievements
Rank 1
Share this question
or