Selectable presets to use as filters

5 posts, 1 answers
  1. LM IT
    LM IT avatar
    9 posts
    Member since:
    Feb 2014

    Posted 07 Oct 2014 Link to this post

    Hey, I'd like to create a combobox which contains filtering presets and then apply the filterdescriptors upon selection change using the MVVM-pattern. I'm able to add default filter descriptors but unable to get the filters updated afterwards programmatically from view-model. Everything is wired as TwoWay and are raising PropertyChanged and is set as UpdateSourceTriggers.

    Preset-collection for the combobox:
    private ObservableCollection<KeyValuePair<string, ObservableCollection<FilterDescriptor>>> filterPresets;
    public ObservableCollection<KeyValuePair<string, ObservableCollection<FilterDescriptor>>> FilterPresets
    { ... }

    Selected item of the Preset-combobox which should update the actual filtering collection upon change:
    private KeyValuePair<string, ObservableCollection<FilterDescriptor>> selectedPreset;
    public KeyValuePair<string, ObservableCollection<FilterDescriptor>> SelectedPreset
    {
        get { return selectedPreset; }
        set
        {
            if (selectedPreset.Key != value.Key)
            {
                selectedPreset = value;
                FilterDescriptors = selectedPreset.Value;
                OnPropertyChanged();
            }
        }
    }

    Actual filter descriptor collection bound to the datafilter using FilterDescriptorBindingBehavior.FilterDescriptors:
    private ObservableCollection<FilterDescriptor> filterDescriptors;
    public ObservableCollection<FilterDescriptor> FilterDescriptors
    { ... }


    Looking forward for your reply,
    LM IT



















  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 08 Oct 2014 Link to this post

    Hello,

    The filter descriptors should be re-evaluated once the chosen item in the collection is changed.
    Have you followed the approach from the Create Custom Filter Editors help article when implementing this custom editor?

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. LM IT
    LM IT avatar
    9 posts
    Member since:
    Feb 2014

    Posted 09 Oct 2014 in reply to Dimitrina Link to this post

    Thanks for the reply. Yeah I've followed the Custom Filter Editors-approach, how do I re-evaluate them?
  5. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 09 Oct 2014 Link to this post

    Hello,

    Basically, each time that something changes on the RadDataFilter.FilterDescriptors, it evaluates the new filtering expression and compares it with the last one that was cached. If they are different, this means that the filtering criteria in RadDataFilter has changed. 

    In case you have done this and there is not any effect, may I ask you to isolate the issue in a demo project and send it to us? You can also take a look at this blog post for a reference on how to isolate an issue. That way we can check it locally and we will be able to advise further.

    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.

     
  6. LM IT
    LM IT avatar
    9 posts
    Member since:
    Feb 2014

    Posted 10 Oct 2014 Link to this post

    If someone else encounters the same issue, Dimitrina solved my problem after looking at my isolated project. Turned out I was missing code below for forcing the datafilter to sync:

            private void PresetComboBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
            {
                var selectedItem = e.AddedItems[0] as FilterListItem;
                if (selectedItem != null)
                {
                    DataFilter.FilterDescriptors.Clear();
                    foreach (var desc in selectedItem.FilterDescriptors)
                    {
                        DataFilter.FilterDescriptors.Add(desc);
                    }
                }
            }
Back to Top
UI for WPF is Visual Studio 2017 Ready