How to filter in Unbound mode

5 posts, 0 answers
  1. Lutz
    Lutz avatar
    19 posts
    Member since:
    Jun 2012

    Posted 17 Mar 2014 Link to this post

    So, when using RadDataFilter in unbound mode, how does the actual filtering get done? I've subscribed to the FilterDescriptor events so I know *when* to do it, but not *how*. Do I need to iterate over the FilterDescriptors and write filtering code myself? I don't see how I can do that, since the only function available on those descriptors is CreateFilterExpression(Expression instance), but I can't find any documentation in the Telerik help on it. What is the instance parameter? Is there a sample that actually demonstrates this?

    - Lutz
  2. Hristo
    Admin
    Hristo avatar
    41 posts

    Posted 20 Mar 2014 Link to this post

    Hi Lutz,

    In order to filter the data when RadDataFilter is in unbound mode, you have to create the properties you want to show in the drop-down and  assign them to ItemPropertyDefinitions. After this is done you have to attach the RadDataFilter's FilterDescriptors to the CollectionChanged event.

    In this event when the action is add, you have to insert a FilterDescriptor to the GridView. When you remove a FilterDescriptor from the DataFilter, you have to remove the corresponding GridView FilterDescriptor.

    I am attaching a sample project demonstrating this approach.

    Regards,
    Hristo
    Telerik
     

    DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges. Watch on demand now.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Lutz
    Lutz avatar
    19 posts
    Member since:
    Jun 2012

    Posted 20 Mar 2014 in reply to Hristo Link to this post

    Thanks for the reply, but I am not using a RadGridView. I want to use RadDataFilter to filter my list, but the list gets used somewhere else (in a custom user control). In that case, would I need to write my own filtering code that iterates over the FilterDescriptors and does the tests, etc.?

    Regards,
    - Lutz
  5. Grigory
    Grigory avatar
    1 posts
    Member since:
    Sep 2014

    Posted 17 Nov 2014 Link to this post

    Hello, i'm having same situation. This control is very useful for creating custom filters. In fact i'm trying to use it for creating query expressions to full text engine (e.x. Solr). So I need to convert resulting IFilterDescriptor tree to my own expression tree.

    It's not a problem. The problem is to track RadDataFilter descriptor changes. When I attach to CollectionChanged event I can see only add/remove events item from root collection. No event is fired when I change filterdescriptor data. Moreover I need to subscribe to CollectionChanged event on EVERY child CompositeFilter collection.

    Finally there is some "strange" code... (so I can wrap this control in my class and use same logic there) But may be there is any other way to achieve same result?


    public MainWindow()
    {
      InitializeComponent();
     
      ServiceProvider.RegisterPersistenceProvider<ICustomPropertyProvider>(typeof(RadDataFilter), new FilterDescriptorCustomPropertyProvider());
     
      var nameDefinition = new ItemPropertyDefinition("Name", typeof(string), "Employee's Name");
      var nameDefinition2 = new ItemPropertyDefinition("SomeProperty", typeof(Value), "Employee's Name");
      RadDataFilter.ItemPropertyDefinitions.Add(nameDefinition);
      RadDataFilter.ItemPropertyDefinitions.Add(nameDefinition2);
      RadDataFilter.FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;
    }
     
    private void FilterDescriptors_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
    {
      if (e.NewItems != null)
      {
        foreach (var filter in e.NewItems.OfType<INotifyPropertyChanged>())
        {
         filter.PropertyChanged += FilterChanged;
          
     
         if (filter is CompositeFilterDescriptor)
         {
           var cFilter = filter as CompositeFilterDescriptor;
           cFilter.FilterDescriptors.CollectionChanged -= FilterDescriptors_CollectionChanged;
           cFilter.FilterDescriptors.CollectionChanged += FilterDescriptors_CollectionChanged;  
         }
        }
      }
     
      if (e.OldItems != null)
      {
        foreach (var filter in e.OldItems.OfType<INotifyPropertyChanged>())
        {
         UnsusbscribeFromEvents(filter);
        }
      }
     
      FilterChanged(null, null);
    }
     
    private void FilterChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
    {
      TextBox.Text += "Filter changed fired\r\n";
    }
     
    private void UnsusbscribeFromEvents(INotifyPropertyChanged filterDescriptor)
    {
     if (filterDescriptor is CompositeFilterDescriptor)
     {
       var cFilterDescriptor = filterDescriptor as CompositeFilterDescriptor;
     
       foreach (var filter in cFilterDescriptor.FilterDescriptors.OfType<INotifyPropertyChanged>())
       {
          UnsusbscribeFromEvents(filter);
       }
     
       cFilterDescriptor.FilterDescriptors.CollectionChanged -= FilterDescriptors_CollectionChanged;
     
     }
     
     filterDescriptor.PropertyChanged -= FilterChanged;
    }




  6. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Nov 2014 Link to this post

    Hi,

    In that case you could subscribe for the ItemChanged event of RadDataFilter. It will be raised as the user changes the FilterDescriptor's data.
     
    For example:

    void FilterDescriptors_ItemChanged(object sender, ItemChangedEventArgs<IFilterDescriptor> e)
    {
        if (e.PropertyName == "Value")
        {
            // do your stuff
        }
        ...
    }

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WPF is Visual Studio 2017 Ready