Hello,
I am using xamDatagrid (Version 16.1 latest service pack) to present an ObservableCollection<myOwnObject>. When I apply filtering and/or sorting and read new data into the observablecollection, the filter filters more data than allowed and sorting does not apply.
By reading postings in this forum I understood that sorting is not applied automatically after adding or changing a record.
http://www.infragistics.com/community/forums/p/61627/314102.aspx#314102
What is the best way to refresh data of an ObservableCollection<T> and reapply filters and sort orders to the new set of data?
It would be great to have a MVVM friendly solution.
Thanks
Niko
Hello Niko, When the records in the XamDataGrid are filtered by a particular Field, adding new DataItems to the DataSource will automatically filter their respective records in or out depending on whether or not they meet the filtering condition. In order to keep the DataSource sorted when new items have been added, you will have to handle the InitializeRecord event and invoke the respective Record's RefreshSortingPosition method. The reason for this behavior not be automated is because if you have many records and you change one of its Fields’ Value, and there is automatic sorting, the Record will be sorted and will go to its new position and you will lose it. I have prepared an MVVM based sample application, where this behavior has been implemented by using a Command for adding a new DataItem to the DataSource of the XamDataGrid. If you require any further assistance on this matter, please do not hesitate to ask.
Hello Tacho,
thanks for the quick response and the example.
I understood that an explicit trigger is neccessary to re-sort data after an insert.
In my situation its not about adding new records and get the sorted (this is something I need very likely in a later phase of this project).
Consider following setup:
1. User loads initial set of data - e.g. filter for region East
2. The user switches from the filter region East to West: In this case I Clear() the ObservableCollection and repopulate it (with the result of a database query) again.
After that I send a OnPropertyChanged() and the new data is correctly displayed, but the sort order is ignored and it seems that the filter does filter too hard - he also hides records that match the filter to condition to be shown.
To extend your example:
this.Employees.Clear(); // Everything empty now
// Loop throug a database result set and add multiple employees from the database
this.Employees.Add( new Employee(Field1, Field2, Field3) );
this.NotifyPropertyChanged("Employees");
Please advice how I can reensure the sort condition and the filter in such a situation.
Hello Niko, I have modified the adding operation you have introduced as a code-snippet and I was not able to reproduce the behavior you have described in regards to ignoring the filtering condition and the sorting of the control when clearing and repopulating the DataSource. Would you please modify the sample application I have attached, so the issue is reproduced and send it back to me for further investigation? It would be great if you could also provide me with detailed steps for reproducing the issue. Having this information will help me further investigate this matter for you. Looking forward to hearing from you.
thanks for the adapted example. This works for me and I modified it to get closer to my application. It still worked.
Then I realized that in my app that there are two datagrids in the same window: One works as expected, the other does not. For that reason I looked into every difference between those two. First on the XAML level, than on the Viewmodel and model.
Finally: I refreshed the two ObservableCollections differently. I am not sure what the reason for that behaivior is.
The buttom line is: It works and the reason is not on xamDatagrid.
Thanks a lot for your support!
Hello Niko,
Thank you for your feedback.I am glad to know that you were able to achieve the functionality you were looking for.
If you require any further assistance on this matter, please do not hesitate to ask.