We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback


Thread ID:





119487 Jun 30,2015 10:27 AM UTC Oct 6,2015 02:25 AM UTC WPF 7
Tags: SfDataGrid
Soumyajit Roy
Asked On June 30, 2015 10:27 AM UTC


I am trying to filter a SfDataGrid collection in my view model code using the following code and it does not work.

private void ApplyFilterToList()
            ICollectionView view = CollectionViewSource.GetDefaultView(list);
            view.Filter += new Predicate<object>(FilterRecords);

private bool FilterRecords(object item)
view is null.

Is there any similar function like the above one which returns the view object associated with the SfDataGrid collection.

Soumyajit Roy

Elavarasan M [Syncfusion]
Replied On July 2, 2015 03:39 AM UTC

Hi Soumyajit,

Thank you for using Syncfusion products.

We have analysed your query and currently we don’t have direct support to apply the filters in view model collectionview. You can bind the collectionview to the grid and filter the grid using Filter predicate in sfdatagrid. We have prepared the sample for Binding CollectionView with SfDataGrid and set the ItemSource as CollectionView to Grid.  Then the Sorting, Filtering, Grouping operations are performed through “SfDataGrid.View”.  Please find the sample from following location:

Sample: http://www.syncfusion.com/downloads/support/forum/119487/ze/SfDataGridSample17393417

Please let us know if you have any queries.

Elavarasan M

Soumyajit Roy
Replied On August 3, 2015 05:08 PM UTC

Thank You for the reply.
Sorry for bit late to follow up.

I have bound the ItemSource of sfDataGrid object to the collection's view
ICollection CollectionView1 = CollectionViewSource.GetDefaultView(records1);  // records1 is the collection

Here is the XAML:
<syncfusion:SfDataGrid x:Name="dg" ItemsSource="{Binding Path=CollectionView1}" />

But in the viewmodel, when I add the filter, the filter does not seem to be applied.
CollectionView1.Filter += new Predicate<object>(FilterRecords);

Any idea?


Jai Ganesh S [Syncfusion]
Replied On August 4, 2015 04:32 PM UTC

Hi Soumyajit,
Thank you for the update.
We have analyzed your query. As we said in our previous update, we don’t have direct support to apply the filters in view model collectionview. However you can achieve your requirement by using custom QueryableCollectionView and overriding FilterRecord method.

GridQueryableCollectionViewWrapper and set it as the itemssource of SfDataGrid. Please find the below code snippet:

Code Snippet:

//itemssource for grid as CustomizedQueryablecollectionviewrapper

private CustomQueryableCollectionViewWrapper collectionView;

public CustomQueryableCollectionViewWrapper CollectionView


get { return collectionView; }



collectionView = value;




//CollectionView is the type of customized GridQueryablecollectionViewWrapper which is the itemssource of sfdatagrid.

(this.datagrid.DataContext as ViewModel).CollectionView = new CustomQueryableCollectionViewWrapper(emp as IEnumerable, ViewModel.SfGridValue);

Please refer the below code snippet to define the SfDataGrid in xaml.
Code Snippet:

<Syncfusion:SfDataGrid x:Name="datagrid"





ItemsSource="{Binding CollectionView}"

local:ViewModel.DataGrid="{Binding ElementName=datagrid}">

Please refer the following code snippet to override GridQueryableCollectionViewWrapper.
Code Snippet:

//customized GridQueryablecollectionViewWrapper

public class CustomQueryableCollectionViewWrapper : GridQueryableCollectionViewWrapper


public CustomQueryableCollectionViewWrapper(IEnumerable source, SfDataGrid grid)

: base(source, grid)



public override bool FilterRecord(object record)


var item = record as BusinessObjects;

            if (item.EmployeeID >10)

                return true;

            return false;


We have also prepared the sample based on this and please find the sample under the following location,
Sample: http://www.syncfusion.com/downloads/support/directtrac/142249/ze/SfDataGridSample-759408692
In the above sample , we have filtered the data if the Employee ID is greater than 10.
Please let us know if you need further assistance.
Thank you,
Jai Ganesh S

Soumyajit Roy
Replied On August 10, 2015 11:35 AM UTC

Hello Jai Ganesh,

Thank you so much your quick response as always. Your solution will work definitely but I had already found an alternate solution. I have passed the CollectionViewAdv from sfDataGrid to my view model and I can add the filter there and it worked.

We can close this thread. 

Kind Regards.
Soumyajit Roy

Jai Ganesh S [Syncfusion]
Replied On August 11, 2015 03:56 AM UTC

Hi Soumyajit,

Thank you for the update.

Please let us know if you need further assistance on this.

Thank you,

Jai Ganesh S

Replied On October 1, 2015 08:37 AM UTC

Hi Soumyajit,

Could you please tell me how you managed to pass the CollectionViewAdv to your model?
Synchfusion's solution is not usable and absolutely not MVVM friendly.


Jai Ganesh S [Syncfusion]
Replied On October 6, 2015 02:25 AM UTC

Hi Soumyajit,

As we already mentioned in our first update, currently we don’t have a direct support to apply the filters in view model collectionview. Hence we have provided the solution to filter a grid using view filter and also provided a solution for overriding   GridQueryableCollectionViewWrapper and apply the filter but in your last update you have  pass the CollectionViewAdv to your model and apply the filter. Could you please share the details for how you pass the CollectionViewAdv to your model or please share the sample for this? This would be more helpful for us.

Please let us know if you have any query.


Jai Ganesh S


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon