[Expand]General Information
[Collapse]WinForms Controls
 [Expand]What's Installed
 [Expand]Build an Application
 [Collapse]Controls and Libraries
  [Expand]Forms and User Controls
  [Expand]Messages, Notifications and Dialogs
  [Expand]Editors and Simple Controls
  [Expand]Ribbon, Bars and Menu
  [Expand]Application UI Manager
  [Expand]Docking Library
  [Expand]Data Grid
  [Expand]Vertical Grid
  [Expand]Property Grid
  [Expand]Pivot Grid
  [Expand]Tree List
  [Expand]Chart Control
  [Expand]Map Control
   [Expand]Product Information
    Product Structure
    Getting Started
   [Expand]Spreadsheet Document
    Supported Formats
   [Expand]Cell Basics
   [Expand]Spreadsheet Formulas
    Defined Names
    Data Binding
    Data Validation
   [Expand]Data Presentation
    Data Grouping
   [Expand]Pivot Table Overview
   [Expand]Charting Overview
   [Expand]Mail Merge Overview
    Find and Replace
   [Expand]Visual Elements
    [Expand]Rows and Columns
    [Expand]Import and Export Data
    [Expand]Data Binding
    [Expand]Mail Merge
    [Expand]Formatting Cells
    [Expand]Conditional Formatting
    [Expand]Group Data
    [Expand]Filter Data
    [Collapse]Pivot Tables
      How to: Create a Pivot Table
      How to: Refresh a Pivot Table
      How to: Change a Data Source for a Pivot Table
      How to: Move a Pivot Table
      How to: Clear or Remove a Pivot Table
      How to: Change the PivotTable Layout
      How to: Subtotal Fields in a Pivot Table
      How to: Display or Hide Grand Totals for a Pivot Table
      How to: Apply a Predefined Style to a Pivot Table
      How to: Apply a Custom Style to a Pivot Table
      How to: Control Style Options
      How to: Change the Summary Function for a Data Field
      How to: Apply a Custom Calculation to a Data Field
      How to: Create a Calculated Field
      How to: Create a Calculated Item
      How to: Sort Items in a Pivot Table
      How to: Filter Items in a Pivot Table
      How to: Group Items in a Pivot Table
  [Expand]Rich Text Editor
  [Expand]Spell Checker
  [Expand]Form Layout Managers
  [Expand]Navigation Controls
  [Expand]PDF Viewer
  [Expand]TreeMap Control
 [Expand]Common Features
  Get More Help
 [Expand]API Reference
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Expand]Office File API
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation

How to: Sort Items in a Pivot Table

The examples below demonstrate how to sort items in PivotTable fields by labels and summary values.

Expanded Sort Item Labels

To sort items in a specific PivotTable field in ascending or descending order, assign the corresponding PivotFieldSortType enumeration member to the PivotField.SortType property.

For example, the following code sorts items of the "Product" field in ascending order.

Show Me

A complete sample project is available in the DevExpress Code Examples database at http://www.devexpress.com/example=T298650.

Expanded Sort Items by Summary Values

Besides sorting item labels, you can also sort items in a row or column field based on values in the data area of the PivotTable report. To do this, call the PivotField.SortItems method for the field you wish to sort and pass the following parameters.

  • A PivotFieldSortType enumeration member that specifies the sort order (ascending or descending).

  • A zero-based index of the data field in the PivotDataFieldCollection collection by which items in the field should be sorted.

  • An array or collection of the PivotItemReference objects that represent references to specific PivotTable items describing a particular row or column in the data area containing values to sort by. If this parameter is not specified, items in the field are sorted by their grand total values.


If you try to apply sorting to a field that is not currently shown as a row or column field in the report, or the sort settings you specify are invalid, an exception occurs. To view sort options applied to a specific field, use the field's PivotField.Sort property.

The following code example shows how to sort products in descending order by sales values in the first quarter.

The following image shows the result of the code's execution.

Is this topic helpful?​​​​​​​