I would like to be able to sort the order of the rows in the XamDataGrid based on the rows source data.
How would I go about doing this with the XamDataGrid, I have been able to do this in the past with both Telerik, and DevExpress grid controls but there does not seem to be a way to do this with the XamDataGrid.
Hi,
If you are using the 12.1 or later version, then you can use the XamDataGrid's FieldLayoutSettings property - SortingEvaluationMode="Manual". Then you can do your custom sorting in the Sorting/Sorted events of the XamDataGrid.
Another way is to use SortingEvaluationMode="UseCollectionView", then your source should inherit from CollectionView and your custom sorting can be done by using CustomSort comparer. After a custom comparer is applied, then you can sort your data by adding a SortDescription.
Here is a link where this type of sorting is explained.
Hope this helps you.
Anastas
Ok this solutions sounds like it might work but I have already tried to use it an cannot figure out how to get the labels (column/field headers) to set the sort direction on click. I still want this to work like SortEvaluationMode="Auto" where you click on the header but the sorting is from the custom sort on the ListCollectionView.
Is there a way to sort the DataRecords/Records directly?
And just a thought for the future. The IComparer that you can attach to the field settings would work perfectly for this if the cellinfo was passed in with a reference to the DataRecord maybe if you added a new SortComparisonType of Record.
What do you mean by "sort the DataRecords/Records directly"?
You can use manual sorting, and EventArgs of Sorting event - which contains the SortDirection.Direction, and Field.Name.
The manual sorting is not really that manual XamDataGrid expects that I will populate the sort descriptions which will allow me to specify different columns other than the one that is clicked but that is not enough for me.
I need to be able to sort by properties on the items in the data source that are not shown in a field on the XamDataGrid.
As for the UseCollectionView how do I start the sorting when i click on a label? When you set the SortEvaluationMode="UseCollectionView" the label click action is set to nothing and does not do anything.
One more thing all my fields are unbound fields.
Hello Ryan,
I am just checking if you require any further assistance on the matter.
I have been looking into your question and I can suggest you look into the following forum thread where Stefan has shown how to use the CollectionViewSource in order to achieve ‘sorting in the data source’ :
http://es.infragistics.com/community/forums/t/63244.aspx
Let me know, if you need any further assistance on this matter.