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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

SfDataGrid filtering and sorting not working after adding item on ViewModel

Thread ID:

Created:

Updated:

Platform:

Replies:

125315 Aug 8,2016 09:34 AM UTC Aug 12,2016 04:37 AM UTC WPF 7
loading
Tags: SfDataGrid
David García
Asked On August 8, 2016 09:34 AM UTC

Hi,


I'm having an issue with the SfDataGrid control but maybe there is another way to do this or to bind it.

I got a SfDataGrid which ItemsSource is an ICollectionView (implemtned as a ListCollectionView). The source collection for it is a ObservableCollection:


private ObservableCollection<Venta> ventas;

public ICollectionView Ventas { get; private set; }


The definition of the SfDataGrid in the XAML is like this:

<Syncfusion:SfDataGrid Name="VentasList" AutoGenerateColumns="False" AllowEditing="False" AllowDeleting="False" AllowSorting="False" AllowFiltering="False"
                                           ItemsSource="{Binding Path=Ventas}" SelectedItem="{Binding Path=Venta}">
                        <Syncfusion:SfDataGrid.Columns>
                            <Syncfusion:GridTextColumn HeaderText="Envasador" MappingName="Lote.Envasador.RazonSocial" AllowSorting="True" AllowFiltering="True" Width="250"/>
                            <Syncfusion:GridTextColumn HeaderText="Lote" MappingName="Lote.NumeroLote" Width="100"/>
                            <Syncfusion:GridDateTimeColumn HeaderText="Fecha" MappingName="FechaVenta" Pattern="ShortDate" Width="100"/>
                            <Syncfusion:GridNumericColumn HeaderText="Kilos" MappingName="Kilos" NumberDecimalDigits="1" NumberGroupSizes="3" Width="100"/>
                            <Syncfusion:GridTextColumn HeaderText="Envase" MappingName="Envase" Width="150"/>
                        </Syncfusion:SfDataGrid.Columns>
                    </Syncfusion:SfDataGrid>


Notice I set for the SfDataGrid that doesn't allow filtering, editing, deleting or sorting and I that I specify the columns I allow to be filtered and sorted (with the specification that column sorting and filtering got priority over the general SfDataGrid).

In a command in the ViewModel I add a new item to the source collection:

this.ventas.Add(item);

This automatically refresh the SfDataGrid including the new element but after this point the SfDataGrid doesn't allow anymore to sort or filter (the filter dialog appears almost in blank).

Is this maybe a wrong approach or why the SfDataGrid lost the ability to sort and filter? I am not using the Add New Item row as I am using the SfDataGrid as a read only control to be able to use the features of sorting, filtering and summary.

The Essential Studio Version is 14.2.0.26

Thanks in advance.

Daniel Fowler
Replied On August 8, 2016 12:57 PM UTC

Hi mate

I don't work for Syncfusion, but I saw your post and thought I'd respond as I faced the same problem.

See the following documentation:
http://help.syncfusion.com/wpf/sfdatagrid/filtering

I think the sfDataGrid has a built in Collection View, all you need to do is to notify the Grid when to call the Filter method.

In my application I have an ObservableCollection set to the ItemsSource of the DataGrid, then use the process described above and it filters nicely (well, not exactly the same - but somethign similar!).


In the Essential Studio there is a DataGrid Filtering example which you can dissect to figure it all out.

Take it easy

-Dan


David García
Replied On August 8, 2016 01:30 PM UTC

Hi,

Thanks for the reply back.

I don't use the programmatic filtering as for me is enough with the built-in filtering provided by the SfDataGrid control. While I don't add elements programmatically the sorting and filtering works perfectly, but if I add a new item programmatically to the source collection then is when the filtering and sorting stops working.

I have tried to change the source collection from ICollectionView to use directly an ObservableCollection but the effect is exactly the same.

Still thanks for the reply and the suggestions.

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 9, 2016 12:29 PM UTC

Hi David,

Thanks for contacting Syncfusion Support.

We have prepared a sample based on your scenario which has ItemSource as ICollectionView that is implemented from the ListCollectionView. But we were unable to reproduce the reported issue. In this sample the Sorting and Filtering operations are working fine after adding the item in Source collection.  

For your reference we have attached the tested sample in the below location. Please revert by modifying the attached sample based on your application along with the replication procedure. It will be helpful to analyze further. 

Sample :  http://www.syncfusion.com/downloads/support/forum/125315/ze/ListCollectionView-292430454

Regards,
Sowndaiyan
 


David García
Replied On August 9, 2016 03:27 PM UTC

Hi,

Thanks for the reply back.

I'm having problems to compile the example but I'm working through it.

Says the tag SfDataGrid doesn't exists in the XML namespace http://schemas.syncfusion.com/wpf.

As said I'm working through it and will back when be able to try and modify the example.

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 11, 2016 03:09 AM UTC

Hi David,

 
Please find the modified sample from the below location. As per our previous update please revert by modifying the attached sample based on your application along with the replication procedure. We will wait to hear from you.

Sample : http://www.syncfusion.com/downloads/support/forum/125315/ze/ListCollectionView1370332602

Regards,
Sowndaiyan
 


David García
Replied On August 11, 2016 02:15 PM UTC

Hi again,

After going through the sample and trying to reproduce the error in it, and going through my project I go to the conclusion that there is some problem with my Entity Framework model classes that is causing the SfDataGrid to lost the ability to sort and filter.

I will go through my project and when found exactly what in my model is causing the problems will reply back just in case someone has the same issue.

Thanks for the provided example as will help me with the issue.

Sowndaiyan Paulpandi [Syncfusion]
Replied On August 12, 2016 04:37 AM UTC

Hi David,

Thank you for the update.  
 
Please let us know when you reproduce the issue in your project and we will be happy to assist you in fixing your issue. 

Regards,
Sowndaiyan
 


CONFIRMATION

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.

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

;