Skip to main content
A newer version of this page is available. .

Sorting Group Rows by Summary Values

  • 4 minutes to read

When the grid’s data is grouped, rows are always sorted against the grouping columns. By default, group rows are sorted in the order specified by the corresponding grouping column. If the grid displays group summaries, group rows can also be sorted by their summary values.

SortGroupRowsBySummary

To sort group rows by their summary values in code:

After this object has been added to the collection, group rows are automatically sorted by their group summary values. To cancel sorting in code, remove this object from the collection.

End-users can sort group rows by summary values using a column header’s context menu. To learn more, see Sorting Group Rows by Summary.

Example

This example shows how to sort group row by summary values.

using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Documents;
using DevExpress.Xpf.Grid;

namespace DXSample_SortGroupsBySummary {
    public partial class Window1 : Window {
        public Window1() {
            InitializeComponent();
            grid.ItemsSource = new AccountList().GetData();
            SortGroupsBySummary(view.GroupedColumns[0]);
        }
        private void SortGroupsBySummary(GridColumn column) {
            GridGroupSummarySortInfo sortInfo = new GridGroupSummarySortInfo(grid.GroupSummary[0],
                column.FieldName, System.ComponentModel.ListSortDirection.Ascending);
            grid.GroupSummarySortInfo.Add(sortInfo);
        }
    }
    public class AccountList {
        public List<Account> GetData() {
            return CreateAccounts();
        }
        private List<Account> CreateAccounts() {
            List<Account> list = new List<Account>();
            list.Add(new Account() { UserName = "Nick White", 
                RegistrationDate = DateTime.Today, Age = 57 });
            list.Add(new Account() { UserName = "Jack Rodman",
                RegistrationDate = new DateTime(2009, 5, 10), Age = 24 });
            list.Add(new Account() { UserName = "Sandra Sherry",
                RegistrationDate = new DateTime(2009, 5, 10), Age = 35 });
            list.Add(new Account() { UserName = "Sabrina Vilk",
                RegistrationDate = DateTime.Today, Age = 19 });
            list.Add(new Account() { UserName = "Mike Pearson",
                RegistrationDate = new DateTime(2008, 10, 18), Age = 42 });
            return list;
        }
    }
    public class Account {
        public string UserName { get; set; }
        public DateTime RegistrationDate { get; set; }
        public int Age { get; set; }
    }
}