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

Filtered Event Not Firing After Filter Set Using Composite Filter Descriptor

6 Answers 209 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jarrod
Top achievements
Rank 1
Jarrod asked on 22 Mar 2011, 11:10 AM
I have a GridViewComboBoxColumn that I have added a Composite Filter descriptor to, so that I can Filter based upon the text description of the combobox rather than the ID's which are the default. I have used the sample here as the basis of my code. The filter works perfectly, but the "Filtered" event is not firing when the composite filter is executed.

Is this normal? I have included my code as an example. Any help would be greatly appreciated.

public partial class SalesStageFilterControl : UserControl, IFilteringControl
{
    private GridViewComboBoxColumn _column;
    private CompositeFilterDescriptor _compositeFilterDescriptor;
 
    public SalesStageFilterControl()
    {
        InitializeComponent();
    }
 
    public static readonly DependencyProperty IsActiveProperty = DependencyProperty.Register("IsActive", typeof(bool), typeof(SalesStageFilterControl), new PropertyMetadata(false));
 
    #region IFilteringControl Members
 
    public bool IsActive
    {
        get{ return (bool)GetValue(IsActiveProperty);}
        set{ SetValue(IsActiveProperty, value);}
    }
 
    #endregion
 
    public void Prepare(GridViewBoundColumnBase column)
    {
        if(_compositeFilterDescriptor == null)
        {
            _compositeFilterDescriptor = new CompositeFilterDescriptor {LogicalOperator = FilterCompositionLogicalOperator.Or};
            _column = column as GridViewComboBoxColumn;
            listBoxSalesStage.ItemsSource = ((ViewModels.OpportunityViewModel)(_column.ItemsSourceBinding.Source)).SalesStages;
            listBoxSalesStage.DisplayMemberPath = _column.DisplayMemberPath;
            listBoxSalesStage.SelectedValuePath = _column.SelectedValueMemberPath;
        }
    }
 
    private void ListBoxSalesStageSelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e)
    {
        _compositeFilterDescriptor.FilterDescriptors.Clear();
        foreach (var item in listBoxSalesStage.SelectedItems)
        {
            var propertyInfo = item.GetType().GetProperty((_column).SelectedValueMemberPath);
            var itemValue = propertyInfo.GetValue(item, null);
            _compositeFilterDescriptor.FilterDescriptors.Add(new FilterDescriptor(_column.DataMemberBinding.Path.Path, FilterOperator.IsEqualTo, itemValue));
        }
 
        if (_compositeFilterDescriptor.FilterDescriptors.Count > 0)
        {
            if (!_column.DataControl.FilterDescriptors.Contains(_compositeFilterDescriptor))
            {
                _column.DataControl.FilterDescriptors.Add(_compositeFilterDescriptor);
            }
            IsActive = true;
        }
        else
        {
            if (_column.DataControl.FilterDescriptors.Contains(_compositeFilterDescriptor))
            {
                _column.DataControl.FilterDescriptors.Remove(_compositeFilterDescriptor);
            }
            IsActive = false;
        
    }
}



6 Answers, 1 is accepted

Sort by
0
Rossen Hristov
Telerik team
answered on 22 Mar 2011, 11:26 AM
Hello Jarrod,

It's quite normal.

When you are developing your own filtering control it is natural that events are not fired. There is no one to fire them. Who will fire them? When the filtering controls is ours -- we know when filtering occurs and we fire them. But when it is yours -- it is up to you. We don't know what is going on in your custom filtering control.

Anyway, you really don't need events, since the control is yours and you know exactly when filtering occurs.

Instead of listening for an event which will never fire, you can listen for RadGridView.FilterDescriptors.CollectionChanged or you can do the thing that you want to do in your custom filtering control before/after filtering occurs.

I hope this makes sense. Let me know if you have any other questions.

Greetings,
Ross
the Telerik team
0
Jarrod
Top achievements
Rank 1
answered on 22 Mar 2011, 11:32 AM
Hi Ross,

I am already using the Filtered Event to fire other activities. I have a second grid control that is a summary of my main control. So the Filtered event is used to fire other activities. 

Is it possible to fire this event manually? or am I going to have to manually wire in the CollectionChangedEvent to then fire into my FilteredEvent handler? 

Thanks for your prompt response.

Jarrod
0
Rossen Hristov
Telerik team
answered on 22 Mar 2011, 01:06 PM
Hello Jarrod,

It is not possible to fire the event manually, since there is not way for us to know when your controls is filtering and what.

You will have to devise a scheme to notify all interested parties that filtering has occurred.

Greetings,
Ross
the Telerik team
0
Jarrod
Top achievements
Rank 1
answered on 22 Mar 2011, 01:20 PM
Hi Ross,

You cannot be serious? That seems very misleading and inconsistent? I mean the event is called the "FilteredEvent" and that is exactly what is happening. A filter event has just occurred, so why is it not firing? you must know, because the grid has just filtered.

Ok so maybe we should start again and look at what my problem is? I have a combo box column in the grid, the underlying data is an integer, but the display is text. Unfortunately the default Filter control is displaying the integer values. I need to display the Text in the default filter control, not the integer values. So that way when the filter is applied it fires the "FilteredEvent" so the rest of my code can execute.

 How do I achieve this?

Jarrod
0
Rossen Hristov
Telerik team
answered on 22 Mar 2011, 01:42 PM
Hello Jarrod,

Events are a way for us to communicate something to you when we know that is has happened. When we don't know that it has happened, we cannot communicate it with you. 

All RadGridView events like Filtered, Sorted, Grouped and so on are only raised from RadGridView's default UI. This is the UI that we have written and we have the source code and we can raise any kind of event because we know that something is happening.

If the UI is non-default, i.e. you have supplied it -- we can't raise these events because we don't know when they occur. 

The Filtered event is raised by the view model serving our stock filtering control. When you replace our stock filtering control with your own -- our filtering control no longer exists. Its view model does not exist either. So there is no one to raise the events.

The bottom-line is: The Filtered event (and many others) will be raised only by RadGridView's default UI. 

If you really need to do this with events, you can create a new event called "Filtered: on your custom filtering control and raise it whenever you feel necessary. Then instead of attaching to RadGridView's Filtered event you can attach to the Filtered event of your custom filtering control.

It will be you telling yourself something by using events. But if that is the way you want to do it, it is up to you.

Regards,

Ross
the Telerik team
0
Jarrod
Top achievements
Rank 1
answered on 22 Mar 2011, 01:56 PM
Hi Ross,

Ok thanks, that is not very helpful because I was utilising your GridViewFilteredEventArgs  and its Removed and Added collections as well. I just would have thought that you would not raise a Filtered Event from the UI, but rather in the underlying grid that is applying the filter. 

It seems like it is a bug to me, your own documentation states: "Filtered - occurs when the grid data has been filtered. The type of the passed event arguments is GridViewFilteredEventArgs". Fundamentally the Grid data has been filtered, what triggers it is seems irrelevant. 

If this is the behaviour, then maybe you should notify people up front of this behaviour. But also maybe you should look at allowing the default UI to deal with columns such as combo-boxes in a more customisable manner.

Regards
Tags
GridView
Asked by
Jarrod
Top achievements
Rank 1
Answers by
Rossen Hristov
Telerik team
Jarrod
Top achievements
Rank 1
Share this question
or