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

SortByCondition Class

Represents a sort condition used to identify the column/row by whose values the other field values will be sorted.

Namespace: DevExpress.Xpf.PivotGrid

Assembly: DevExpress.Xpf.PivotGrid.v19.2.dll

Declaration

public class SortByCondition :
    DXFrameworkContentElement

Remarks

To identify the column/row by whose values their values will be sorted, pivot grid fields hold the PivotGridField.SortByConditions collection, which contains the SortByCondition objects.

A sort condition represents a field value. The PivotGridField.SortByConditions collection contains one sort condition for each field in the current Header Area. Together, these conditions identify the required column/row. For instance, the highlighted column on the image below is identified by three sort conditions.

pivotgrid_SortByCondition

The field value which the sort condition represents is specified by the SortByCondition.Value property. The field to which the value belongs is specified by the SortByCondition.Field property.

If the pivot grid is bound to an OLAP data source, the field value is identified by the corresponding OLAP member’s unique name (SortByCondition.OlapUniqueMemberName). In this instance, the SortByCondition.Value property is set to null.

Example

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 SortByCondition 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 PivotGridField.SortByConditions collection to specify the column by which Product Name values should be sorted. A data field that identifies the column is specified via the PivotGridField.SortByField property.

using System.Windows;
using DevExpress.Xpf.PivotGrid;

namespace DXPivotGrid_SortBySummary {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
            pivotGridControl1.DataSource = 
                (new nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData();
        }
        private void pivotGridControl1_Loaded(object sender, RoutedEventArgs e) {

            // Locks the pivot grid from updating while the Sort by Summary
            // settings are being customized.
            pivotGridControl1.BeginUpdate();
            try {

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

                // Specifies a column by which the Product Name field values should be sorted.
                fieldProductName.SortByConditions.Add(new SortByCondition(fieldYear, "1994"));
                fieldProductName.SortByConditions.Add(new SortByCondition(fieldMonth, "9"));
            }
            finally {

                // Unlocks the pivot grid and applies changes.
                pivotGridControl1.EndUpdate();
            }
        }
    }
}

The following code snippets (auto-collected from DevExpress Examples) contain references to the SortByCondition class.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also