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

Sort Groups by Summary Values

  • 2 minutes to read

When ASPxGridView data is grouped, data rows are always sorted against the grouped column. By default, data rows are sorted in the order specified by the grouped column’s GridViewDataColumn.SortOrder property.

Group rows can also be sorted by their summary values. To do this, you should create a new DevExpress.Web.ASPxGroupSummarySortInfo object, customize its settings and add it to the grid’s ASPxGridView.GroupSummarySortInfo collection. Once this object has been added to the collection, group rows are automatically sorted by their summary values. To cancel sorting, remove this object from the collection.

The ASPxGroupSummarySortInfo class provides the following properties:

  • GroupColumn - specifies the name of the data source field that is assigned to the grouped column;
  • Sort Order - specifies the sort order;
  • SummaryItem - represents the summary item used to calculate summary values.

 

This example shows how to sort group rows by summary values, so that countries having the maximum sales amount appear on the top of the view.

The image below shows the result:

exGroupSummarySort

using DevExpress.Data;
using DevExpress.Web.ASPxGridView;

protected void Page_Load(object sender, EventArgs e) {
    grid.GroupSummarySortInfo.Clear();

    ASPxGroupSummarySortInfo sortInfo = new ASPxGroupSummarySortInfo();
    sortInfo.SortOrder = ColumnSortOrder.Descending;
    sortInfo.SummaryItem = grid.GroupSummary["Sales", SummaryItemType.Sum];
    sortInfo.GroupColumn = "Country";

    grid.GroupSummarySortInfo.AddRange(sortInfo);
}