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

Selectable presets to use as filters

4 Answers 119 Views
DataFilter
This is a migrated thread and some comments may be shown as answers.
LM IT
Top achievements
Rank 2
LM IT asked on 07 Oct 2014, 10:53 AM
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



















4 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 08 Oct 2014, 04:19 PM
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.

 
0
LM IT
Top achievements
Rank 2
answered on 09 Oct 2014, 07:03 AM
Thanks for the reply. Yeah I've followed the Custom Filter Editors-approach, how do I re-evaluate them?
0
Accepted
Dimitrina
Telerik team
answered on 09 Oct 2014, 07:19 AM
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.

 
0
LM IT
Top achievements
Rank 2
answered on 10 Oct 2014, 08:16 AM
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);
                }
            }
        }
Tags
DataFilter
Asked by
LM IT
Top achievements
Rank 2
Answers by
Dimitrina
Telerik team
LM IT
Top achievements
Rank 2
Share this question
or