Skip to main content

How to: Sort Data by Individual Columns (Rows)

  • 3 minutes to read

The following example demonstrates how to sort data by a particular column.

In this example, values of the Product Name field are sorted by September 1994 column summary values. To do this, two sort conditions represented by PivotGridFieldSortCondition instances are created. One of them identifies the ‘1994’ field value, while another identifies the ‘September’ value. These sort conditions are added to the Product Name field’s PivotGridFieldSortBySummaryInfo.Conditions collection to specify the column by which Product Name values should be sorted. A data field that identifies the column is specified via the PivotGridFieldSortBySummaryInfo.Field property.

using System;
using System.Web.UI;
using DevExpress.XtraPivotGrid;

namespace ASPxPivotGrid_SortBySummary {
    public partial class _Default : Page {
        protected void ASPxPivotGrid1_Load(object sender, EventArgs e) {

            // Specifies a data field whose summary values should be used to sort values
            // of the Product Name field.
            fieldProductName.SortBySummaryInfo.Field = fieldUnitPrice;

            // Specifies a column by which the Product Name field values should be sorted.
            fieldProductName.SortBySummaryInfo.Conditions.Clear();
            fieldProductName.SortBySummaryInfo.Conditions.Add(
                new PivotGridFieldSortCondition(fieldOrderYear, "1994"));
            fieldProductName.SortBySummaryInfo.Conditions.Add(
                new PivotGridFieldSortCondition(fieldOrderMonth, "9"));
        }
    }
}