Greetings
I have a xamgrid in which I would like to always have the last column sorted in descending order. the data changes quite frequently but I want those changes to be reflected in the grid when they do change. How do I make it so that the last column is always sorted? I thought I needed to use the issorted property but it looks like not.
<ig:XamGrid x:Name="SideGrid" Grid.Row="2" Grid.ColumnSpan="2" ItemsSource="{Binding}" AutoGenerateColumns="False" > <ig:XamGrid.Columns> <!--<ig:TextColumn HeaderText="Bus Rank"/>--> <ig:TextColumn HeaderText="Number" Key="Number" Width="90" IsSortable="False"/> <ig:TextColumn HeaderText="Load" Key="Load" Width="*" IsSorted="Descending"/> </ig:XamGrid.Columns> <ig:XamGrid.SortingSettings> <ig:SortingSettings ShowSortIndicator="False"/> </ig:XamGrid.SortingSettings>
Hello Matthew,
Thank you for posting!
I made a sample project where I set the IsSorted property of the TextColumn to Descending. When new record is added using the AddNewRecord functionality or new data item is added to the source collection using the top button, a row is added in the correct position respecting the sorting of the ProductID column. Could you try to run the attached project and let me know if it works as expected on your side? Do the data changes take effect on the grid so that new rows are added when you run your project? If not, you might want to check whether the xamGrid is notified for these changes by implementing INotifyPropertyChage interface.
Your example worked on my end indeed. However, I think my problem stems from the fact that I'm not adding new items to the grid like you are doing. I have the same items in the grid but I'm updating them at the rate of around every 16.7 milliseconds. So as the grid works now I can see all the items being updated. They just need to resort themselves every time the items change. Does that make sense?
Matthew,
Thank you for the details you have provided information. I understand that you are changing values of the existing data items not adding new ones. The sorting is applied when the grid loads and default sorting description is added or when user interact sort it using the SortIndicator. It does not re-sort when data item is changed because it is not notified that it have to. You could sort a column at runtime by setting the IsSorted property after data is modified. Please note that if the SortDirection is already set the same value e.g. Descending, you should first change it to None or Ascending and then to Descending. Here is a code snippet that demonstrates how this could be achieved on button click:
private void Button_Click_1(object sender, RoutedEventArgs e)
{
DataUtil.Products.ElementAt(5).ProductID = -29;
TextColumn customSortColumn = xamGrid1.Columns[0] as TextColumn;
customSortColumn.IsSorted = SortDirection.None;
customSortColumn.IsSorted = SortDirection.Descending;
}
I hope this will help you.
I am just checking if you have any other questions regarding the sorting functionality of XamDataGrid.
I have a similar sorting issue with XamGrid bound to ObservableCollection and the underlying object implements INotifyPropertyChanged interface. All the fields that change do post PropertyChanged event but still Grid sorting is getting messed up (I have to resolve this bug on our application).
You mentioned that grid is not getting notified of change when the items change(to re-initiate sort), how do I go about doing that even though PropertyChanged Notification message is getting sent? Any suggestion?
or is the grid not listening to change notification to re-do the sorting kindof like feature cutting to show faster performance?
Thanks
Rajeswari
Hello Michael,
The address of the link above was wrong. It is now updated and should be opening correct. Thank you for mentioning it.The sorting is not automatically applied when the data is updated as this might result in a row that is just being updated by the user going out of view. This is the reason that the sorting should be reapplied when the data is updated e.g. on CellExitedEditMode when a user update the cell or on InitializeRow when a new row is added.
Hi Maria,
We have a similar where existing row are updated frequently and one of the columns has the IsSorted property set to Ascending.
From a best-practices approach, what is the preferred way to keep the grid in the correct sorted order?
...the row order changes as column data, with IsSorted, is updated.
Regards,
Michael Perini
The link above is no longer valid.
Thank you,
Michael
Hi Raji,
XamGrid sorting is not automatically updated when the underlying object changes. You might want to have a look at the following forum thread where similar issue is discussed: http://es.infragistics.com/community/forums/p/56936/292575.aspx