Back to Devexpress

PivotGridField.SortByField Property

wpf-devexpress-dot-xpf-dot-pivotgrid-dot-pivotgridfield-4370ee39.md

latest5.7 KB
Original Source

PivotGridField.SortByField Property

Gets or sets the field whose summary values define the order in which the field’s values are arranged. This is a dependency property.

Namespace : DevExpress.Xpf.PivotGrid

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

NuGet Package : DevExpress.Wpf.PivotGrid

Declaration

csharp
public PivotGridField SortByField { get; set; }
vb
Public Property SortByField As PivotGridField

Property Value

TypeDescription
PivotGridField

A PivotGridField object that represents the field whose summary values define the order in which the field’s values are arranged. Note that this field should be placed in Data Header Area.

|

Remarks

To sort data by summaries, do the following:

To learn more, see Sorting by Summary.

Example

This example shows how to sort data by Grand Total values.

In this example, values of the Sales Person field are sorted by the Grand Total column. To do this, the data field by whose values the sorting should be performed (the Order Amount field) is assigned to the Sales Person field’s PivotGridField.SortByField property.

xaml
<Window x:Class="HowToBindToMDB.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:dxpg="http://schemas.devexpress.com/winfx/2008/xaml/pivotgrid"
        Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded">
    <Grid>
        <dxpg:PivotGridControl HorizontalAlignment="Left" Name="pivotGridControl1" 
                               VerticalAlignment="Top">
            <dxpg:PivotGridControl.Fields>
                <dxpg:PivotGridField Name="fieldMonth" FieldName="OrderDate" Area="RowArea"
                                     Caption="Order Month" GroupInterval="DateMonth" />
                <dxpg:PivotGridField Name="fieldSalesPerson" FieldName="Sales Person" Area="RowArea"
                                     SortByField="{Binding ElementName=fieldOrderAmount}"
                                     Caption="Sales Person" SortOrder="Descending"/>                
                <dxpg:PivotGridField Name="fieldOrderAmount" FieldName="Extended Price" Area="DataArea"
                                     Caption="Order Amount" CellFormat="c0" />
            </dxpg:PivotGridControl.Fields>
        </dxpg:PivotGridControl>
    </Grid>
</Window>

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the SortByField property.

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.

wpf-pivot-grid-show-top-n-values-in-context-menu/CS/ContextMenuToShowTopN_Example/MainWindow.xaml.cs#L81

csharp
f.SortOrder = FieldSortOrder.Descending;
f.SortByField = valueItem.DataField;
f.SortByConditions.Clear();

wpf-pivot-grid-show-top-n-values-in-context-menu/VB/ContextMenuToShowTopN_Example/MainWindow.xaml.vb#L78

vb
f.SortOrder = FieldSortOrder.Descending
f.SortByField = valueItem.DataField
f.SortByConditions.Clear()

See Also

PivotGridField Class

PivotGridField Members

DevExpress.Xpf.PivotGrid Namespace