Back to Devexpress

PivotGridField.SortByConditions Property

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridfield-29f7ba0f.md

latest7.5 KB
Original Source

PivotGridField.SortByConditions Property

Contains conditions that identify the column or row whose values are sorted.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public SortByConditionCollection SortByConditions { get; }
vb
Public ReadOnly Property SortByConditions As SortByConditionCollection

Property Value

TypeDescription
SortByConditionCollection

The collection whose items identify the column or row of values to be sorted.

|

Remarks

To sort data by summaries, do the following:

To learn more, see Sorting by Summary.

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.

csharp
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();
            }
        }
    }
}
xaml
<Window xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:Class="DXPivotGrid_SortBySummary.MainWindow"
        Height="600" Width="800" Title="Main Window">
    <Grid>
        <dxpg:PivotGridControl Name="pivotGridControl1" Loaded="pivotGridControl1_Loaded">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldUnitPrice" FieldName="UnitPrice" Area="DataArea"/>
                <dxpg:PivotGridField Name="fieldYear" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Year" GroupInterval="DateYear"/>
                <dxpg:PivotGridField Name="fieldMonth" FieldName="OrderDate" Area="ColumnArea"
                                     Caption="Month" GroupInterval="DateMonth"/>
                <dxpg:PivotGridField Name="fieldCategoryName" FieldName="CategoryName"
                                     Area="RowArea" Caption="Category"/>
                <dxpg:PivotGridField Name="fieldProductName" FieldName="ProductName"
                                     Area="RowArea" Caption="Product"/>
                <dxpg:PivotGridField Name="fieldQuantity" FieldName="Quantity" Area="DataArea"/>
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>
vb
Imports Microsoft.VisualBasic
Imports System.Windows
Imports DevExpress.Xpf.PivotGrid

Namespace DXPivotGrid_SortBySummary
    Partial Public Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
            pivotGridControl1.DataSource = _
                (New nwindDataSetTableAdapters.SalesPersonTableAdapter()).GetData()
        End Sub
        Private Sub pivotGridControl1_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

            ' 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()
            End Try
        End Sub
    End Class
End Namespace

See Also

PivotGridField Class

PivotGridField Members

DevExpress.Xpf.PivotGrid Namespace