Back to Devexpress

Sorting Group Rows by Summary Values

wpf-6144-controls-and-libraries-data-grid-sorting-sorting-group-rows-by-summary-values.md

latest3.7 KB
Original Source

Sorting Group Rows by Summary Values

  • Dec 28, 2023
  • 2 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.

To sort group rows by their summary values in code:

Note

Group rows can be sorted against one summary at a time.

Remove the GridGroupSummarySortInfo object from the GroupSummarySortInfo collection to clear the summary sorting.

Users can sort group rows by summary values through a column header’s context menu.

Refer to the following help topic for more information: Sorting Group Rows by Summary.

Example

This example demonstrates how to sort group rows by summary values in code:

View Example: Sort Group Rows by Summary Values

cs
public partial class Window1 : Window {
    public Window1() {
        InitializeComponent();
        grid.ItemsSource = AccountList.GetData();
        SortGroupsBySummary(view.GroupedColumns[0]);
    }
    void SortGroupsBySummary(GridColumn column) {
        GridGroupSummarySortInfo sortInfo = new GridGroupSummarySortInfo(grid.GroupSummary[0],
            column.FieldName, System.ComponentModel.ListSortDirection.Ascending);
        grid.GroupSummarySortInfo.Add(sortInfo);
    }
}
vb
Public Partial Class Window1
    Inherits Window

    Public Sub New()
        Me.InitializeComponent()
        Me.grid.ItemsSource = AccountList.GetData()
        Me.SortGroupsBySummary(Me.view.GroupedColumns(0))
    End Sub

    Private Sub SortGroupsBySummary(ByVal column As GridColumn)
        Dim sortInfo As GridGroupSummarySortInfo = New GridGroupSummarySortInfo(Me.grid.GroupSummary(0), column.FieldName, System.ComponentModel.ListSortDirection.Ascending)
        Me.grid.GroupSummarySortInfo.Add(sortInfo)
    End Sub
End Class
xaml
<dxg:GridControl x:Name="grid">
    <dxg:GridColumn FieldName="UserName"/>
    <dxg:GridColumn FieldName="RegistrationDate" GroupIndex="0"/>
    <dxg:GridColumn FieldName="Age"/>
    <dxg:GridControl.View>
        <dxg:TableView x:Name="view" AutoWidth="True"/>
    </dxg:GridControl.View>
    <dxg:GridControl.GroupSummary>
        <dxg:GridSummaryItem FieldName="Age" SummaryType="Max"/>
    </dxg:GridControl.GroupSummary>
</dxg:GridControl>