Add FilterDescriptorCollection

10 posts, 0 answers
  1. Peter
    Peter avatar
    51 posts
    Member since:
    May 2016

    Posted 12 May Link to this post

    Hi,
    if I add 2 FilterDescriptor with same propertyname, I get an exception:

    An unhandled exception of type 'System.ArgumentException' occurred in mscorlib.dll
    Additional information: Ein Element mit dem gleichen Schlüssel wurde bereits hinzugefügt.
    (
    An element with the same key has already been added.)

    Stacktrace:

       bei System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
       bei System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
       bei Telerik.Data.Expressions.ExpressionContext.Add(String key, Object value)
       bei Telerik.WinControls.UI.RadTreeViewElement.EvalFilter(RadTreeNode node)
       bei Telerik.WinControls.UI.TreeNodeView.UpdateView()
       bei Telerik.WinControls.UI.RadTreeNodeCollection.Update()
       bei Telerik.WinControls.UI.RadTreeViewElement.UpdateNodes()
       bei Telerik.WinControls.UI.RadTreeViewElement.filterDescriptors_CollectionChanged(Object sender, NotifyCollectionChangedEventArgs e)
       bei Telerik.Collections.Generic.NotifyCollection`1.OnCollectionChanged(NotifyCollectionChangedEventArgs args)
    ...

    Code:

        var fdc = new FilterDescriptorCollection();
    fdc.Add(new FilterDescriptor("Time", FilterOperator.IsGreaterThanOrEqualTo, new DateTime(2017, 1, 1)));
    fdc.Add(new FilterDescriptor("Time", FilterOperator.IsLessThanOrEqualTo, new DateTime(2017, 3, 31)));
    fdc.Add(new FilterDescriptor("Location_Id", FilterOperator.IsEqualTo, 2));
    this.radDataFilter1.FilterDescriptors.AddRange(fdc);

     

    It works, if I calculate the Expressionstring:

    this.radDataFilter1.Expression = fdc.Expression;

     

    What is the correct way to initialize a Datafilter by code?

    Peter

     

  2. Dess
    Admin
    Dess avatar
    2101 posts

    Posted 16 May Link to this post

    Hello Peter, 

    Thank you for writing.  

    It is not valid to manipulate the RadDataFilter.FilterDescriptors collection because it actually will try to filter the RadDataFilter itself. That is why it is hidden from the IntelliSense. If you need to load some filter expression in RadDataFilter it is necessary to use the Expression property. Additional information is available in the following help articles: 
    http://docs.telerik.com/devtools/winforms/datafilter/working-with-descriptor-items/descriptor-items
    http://docs.telerik.com/devtools/winforms/datafilter/working-with-descriptor-items/data-binding
    http://docs.telerik.com/devtools/winforms/datafilter/working-with-descriptor-items/unbound-mode 

    I hope this information helps. Should you have further questions I would be glad to help.

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  3. Peter
    Peter avatar
    51 posts
    Member since:
    May 2016

    Posted 17 May Link to this post

    Hello Dess,
    the filter Expression works good. There is yet a little Problem:

    The Filter for DateTime Columns show only the Date and not the time. Code to add the filter:

    for (int i = 0; i < this.radVirtualGrid1.ColumnCount; i++) { //set correct Type for Filter
         var type = this.cache.CacheTable.Columns[i].DataType;  //CacheTable is a DataTable
         var name = this.cache.CacheTable.Columns[i].ColumnName;
         this.radVirtualGrid1.MasterViewInfo.SetColumnDataType(i, type);
         this.radDataFilter1.Descriptors.Add(new DataFilterDescriptorItem(name, type)) ;
     }
    this.radDataFilter1.Expression = filter;

     

    The Expression has time values: [Time] >= #06/03/2016 21:11:00# AND [Time] <= #06/04/2016 07:53:00# AND [Location_Id] = 2 AND [Status] = 64

    How can I set a format string for the datetime filter or the datepicker of the filters?

    Regards,
    Peter

     

  4. Dess
    Admin
    Dess avatar
    2101 posts

    Posted 18 May Link to this post

    Hello Peter, 

    Thank you for writing back. 

    You can use the DataFilterElement.DefaultCustomDateEditorFormat property to specify the desired format for the dates if the DefaultDateEditorFormat property is set to DateTimePickerFormat.Custom:
    this.radDataFilter1.DataFilterElement.DefaultDateEditorFormat = DateTimePickerFormat.Custom;
    this.radDataFilter1.DataFilterElement.DefaultCustomDateEditorFormat = "MM/dd/yyyy hh:mm:ss";

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  5. Peter
    Peter avatar
    51 posts
    Member since:
    May 2016

    Posted 18 May Link to this post

    Hello Dess,

    it work perfect!  "dd/MM/yy hh:mm:ss" works for the Textbox. But if I click in it, the texbox change to the Combobox part of the datepicker - but with no seconds and yyyy:  "dd/MM/yyyy hh:mm".  Now I don't need second, so I better use "dd/MM/yyyy hh:mm" - than both have the same format.

    It is possible, that the datepicker edit control use the same format of the textbox  in none edit mode?

    Peter

     

  6. Dess
    Admin
    Dess avatar
    2101 posts

    Posted 19 May Link to this post

    Hello Peter, 

    Thank you for writing back. 

    The DateTime format seems to be identical on my end. Please refer to the attached screenshot. I have attached my sample project. Feel free to modify it in a way to reproduce the experienced issue and get back to me with it so I can investigate the precise case. Thank you in advance. 

    I am looking forward to your reply.

      
    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  7. Peter
    Peter avatar
    51 posts
    Member since:
    May 2016

    Posted 19 May Link to this post

    Hello Dess,

    also in your screenshot you can not edit the seconds. I attached my screenshot from german system.

    Interesting: The Date seperator changed from . to /.in the readonly textbox.

    And in Editor the systems default short date and time format is used. I changed the default short time format alos with seconds and now seconds are available in Editor.

    Regards,

    Peter

  8. Dess
    Admin
    Dess avatar
    2101 posts

    Posted 19 May Link to this post

    Hello Peter, 

    Thank you for writing back. 

    You can specify explicitly the custom format for the editor as well in the EditorInitialized event and thus obtain the seconds in the editable part: 
    private void RadDataFilter1_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e)
    {
        TreeViewDateTimeEditor editor = e.Editor as TreeViewDateTimeEditor;
        if (editor != null)
        {
            BaseDateTimeEditorElement el = editor.EditorElement as BaseDateTimeEditorElement;
            el.Format = DateTimePickerFormat.Custom;
            el.CustomFormat = "MM/dd/yyyy hh:mm:ss";
        }
    }

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
  9. Peter
    Peter avatar
    51 posts
    Member since:
    May 2016

    Posted 19 May Link to this post

    Hi Dess,

    perfect. So the TreeViewDateTimeEditor can use the format from DataFilterElement:

    this.radDataFilter1.DataFilterElement.DefaultDateEditorFormat = DateTimePickerFormat.Custom;
    this.radDataFilter1.DataFilterElement.DefaultCustomDateEditorFormat = "dd/MM/yy HH:mm:ss";
    this.radDataFilter1.EditorInitialized += RadDataFilter1_EditorInitialized;
    }
     
    private void RadDataFilter1_EditorInitialized(object sender, TreeNodeEditorInitializedEventArgs e) {
        var dataFilterElement = sender as Telerik.WinControls.UI.RadDataFilterElement;
        var editor = e.Editor as TreeViewDateTimeEditor;
        if (editor != null && dataFilterElement != null) {
            BaseDateTimeEditorElement el = editor.EditorElement as BaseDateTimeEditorElement;
            el.Format = dataFilterElement.DefaultDateEditorFormat;
            el.CustomFormat = dataFilterElement.DefaultCustomDateEditorFormat;
        }
    }

     

    Regards,

    Peter

  10. Dess
    Admin
    Dess avatar
    2101 posts

    Posted 22 May Link to this post

    Hello Peter, 

    Thank you for writing back. 

    Indeed, you can use the same format in the TreeViewDateTimeEditor as in the DefaultCustomDateEditorFormat property. Thus, you will have identical date format.

    I hope this information helps. If you have any additional questions, please let me know. 

    Regards,
    Dess
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top