Custom filter with 2 controls

7 posts, 0 answers
  1. Massimo
    Massimo avatar
    21 posts
    Member since:
    Apr 2013

    Posted 21 Apr 2015 Link to this post

    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>

  2. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 22 Apr 2015 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Massimo
    Massimo avatar
    21 posts
    Member since:
    Apr 2013

    Posted 28 Apr 2015 in reply to Stefan X1 Link to this post

    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

  5. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 01 May 2015 Link to this post

    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.

     
  6. Thomas
    Thomas avatar
    2 posts
    Member since:
    Jun 2016

    Posted 14 Oct in reply to Stefan X1 Link to this post

    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?

  7. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 19 Oct Link to this post

    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.
  8. Stefan X1
    Admin
    Stefan X1 avatar
    523 posts

    Posted 25 Oct Link to this post

    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!
Back to Top
UI for WPF is Visual Studio 2017 Ready