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

Support for the ICollectionView Filter property

7 Answers 707 Views
GridView
This is a migrated thread and some comments may be shown as answers.
BF1468901
Top achievements
Rank 1
BF1468901 asked on 12 Dec 2013, 08:26 AM
Hello

I really appreciate the Rad Grid View filtering and grouping possibilities, but I have such case that I need to filter the source collection before it goes to your control. So I need in fact two filters, first I filter in code the collection and then I filter this filtered collection by your Rad Grid View.

So simply I have my ObservableCollection which is bounded to the Rad Grid View ItemsSource property. Then I am getting the collection view  by the CollectionViewSource.GetDefaultView() method and I am applying there my custom filter to the Filter property.

The problem is that the Rad Grid View seems to not react on that change. So my question is do you support such approach? What else can I do to filter my item before I can filter them by the control UI?

Thank you for help.

My Rad Grid View XAML:

<telerikControls:RadGridView
        HorizontalAlignment="Stretch"
        ItemsSource="{Binding myCollection}"
        SelectedItem="{Binding mySelectedItem, Mode=OneWayToSource}"
        IsReadOnly="True"
        CanUserFreezeColumns="False"
        AutoGenerateColumns="False"
        RowIndicatorVisibility="Collapsed">

7 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 12 Dec 2013, 08:41 AM
Hi,

You can apply FilterDescriptors for the source collection (ICollectionView) itself. Those FilterDescriptors will be synchronized with RadGridView.FilterDescriptors. 

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
BF1468901
Top achievements
Rank 1
answered on 12 Dec 2013, 09:06 AM
Thank you for your answer. Sorry, but I am searching and searching and I am not able to find out how I can obtain from my ObserableCollection the QueryableCollectionView on which I can apply the FilterDescriptors. Is there any extension method that you provide for the System.Windows.Data.CollectionViewSource?
0
BF1468901
Top achievements
Rank 1
answered on 12 Dec 2013, 09:14 AM
Thank you for your answer. Sorry, but I am searching and searching and I am not able to find out how I can obtain from my ObserableCollection the QueryableCollectionView on which I can apply the FilterDescriptors. Is there any extension method that you provide for the System.Windows.Data.CollectionViewSource? I am using .NET 4.0
0
Dimitrina
Telerik team
answered on 12 Dec 2013, 09:16 AM
Hi,

The CollectionViewSource.DefaultView() returns ICollectionView, so you can directly assign its FilterDescriptors.

Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
BF1468901
Top achievements
Rank 1
answered on 12 Dec 2013, 09:22 AM
I have the ICollectionView, but this object do not have the FilterDescriptors property.
http://msdn.microsoft.com/en-us/library/system.componentmodel.icollectionview(v=vs.110).aspx
0
Accepted
Dimitrina
Telerik team
answered on 12 Dec 2013, 11:13 AM
Hi,

Indeed, you are right. 
When using ICollectionView you can set the filter similar to:
var view = CollectionViewSource.GetDefaultView(Mycollection);
this.playersGrid.ItemsSource = view;

view.Filter = (o) => ((MyBusinessObject)o).Country ==
"Spain";

Please make sure that the ItemsSource of RadGridView is already set, so that the filter to take effect.

Do you set the view.Filter differently?

If you would like to wrap it into a QueryableCollecitonView, you can do it like so:
var view = CollectionViewSource.GetDefaultView(Mycollection);
QueryableCollectionView queryableView = new QueryableCollectionView(view);
 
this.playersGrid.ItemsSource = queryableView;

Then add a FilterDescriptor. For example:
queryableView.FilterDescriptors.Add(new FilterDescriptor("Country", FilterOperator.IsEqualTo, "England"));


Regards,
Didie
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
BF1468901
Top achievements
Rank 1
answered on 12 Dec 2013, 12:21 PM
Thank you for answer. It works now, the only one difference in my approach was that I was not setting the ICollectionView object in the ItemsSource property of my Rad Grid View. Thank you for help.
Tags
GridView
Asked by
BF1468901
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
BF1468901
Top achievements
Rank 1
Share this question
or