I'm creating a xamDataGrid that groups by a name column. This works perfectly, but the sort order on the group headers seems to be alphabetical and applying a sort order by the date column only sorts the rows within the groups, it doesn't re-order the group headers themselves into date order.
Is there any way to do this or am I heading down a dead-end?
I'm also interested in this. In my case I have a date field i would like grouped and sorted descending instead of ascending.
@rp8049: I am sorry, I did not quite understood what you are trying to achieve. Can you please provide more information (screenshot,sample,steps to reproduce) about this problem.
@JoeGershgorin:
Have you tried the direction property of the SortDescription.
If the user is grouping, you can use the Grouping event:
void xamDataGrid1_Grouping(object sender, Infragistics.Windows.DataPresenter.Events.GroupingEventArgs e)
{
e.Groups[0].Direction = System.ComponentModel.ListSortDirection.Descending;
}
If the XamDataGrid is loaded as grouped, you should set this in the FieldLayout sorted fields collection.
Regards,
Alex.
On a sub note to ordering by GroupBy fields, is it possible to order the groups according to how many items each contains? So if I have a list of items, with owners, if I group by owner, can I then apply a sort so that the owner with the most items comes top of the list etc...
Yes this is possible using GroupByComparer for particular field. For more details check out the attached sample application showing two ways how this could be implemented.
I hope this helps
-Vlad
Thanks for that, the group by count comparer works a treat! One thing though, I'm setting the GrouByComparer property programatically when a user selects the option to sort in this way, but when they deselect the option, and I set the GroupByComparer back to null, it doesn't reset to alphabetical sorting, the count sort remains. Is there another way to do this?
Cheers!
Hi Rob,
In this case you can try with the ClearValue method:
xamDataGrid1.FieldLayouts[0].Fields[1].Settings.ClearValue(FieldSettings.GroupByComparerProperty);
Best regards
Vlad
I have used this GroupByComparer example to achieve groups are then sorted by record count using a checkbox. However, if filtering is also allowed and the user puts any kind of filtering on the data, the sort by count will not be in the correct order.
Is there any suggestion or explanation you can give to allow grouping and sorting by count both with filters?
Thanks,
//abissette
Rob,
Another option is to save the default comparer using GroupByComparerResolved. For example if you have a checkbox that is used for switching between the default comparer and the custom GroupByRecordCountComparer then you can use the following snippet:
public partial class Window1 : Window{ public IComparer defaultComparer; public Window1() { InitializeComponent(); Loaded += new RoutedEventHandler(Window1_Loaded); } void Window1_Loaded(object sender, RoutedEventArgs e) { .... defaultComparer = xamDataGrid1.FieldLayouts[0].Fields[0].GroupByComparerResolved; } private void check_Checked(object sender, RoutedEventArgs e) { xamDataGrid1.FieldLayouts[0].Fields[1].Settings.GroupByComparer = new GroupByRecordCountComparer(); } private void check_Unchecked(object sender, RoutedEventArgs e) { xamDataGrid1.FieldLayouts[0].Fields[1].Settings.GroupByComparer = defaultComparer; }}
Best regards,
I've put together a work around, where I go through the SortedFields collection of the FieldLayout for the grid, and store each of the fields in a list. Then clear the SortedFields collection, and go through re-adding the fields from the list.
This causes the grid to update its display and allows me to change the sort type on the fly.
Unfortunately, that still doesn't seem to reset the sort type. Does the grid somehow cache the sort order or something?