Back to Devexpress

PivotField.SortType Property

officefileapi-devexpress-dot-spreadsheet-dot-pivotfield-1d35c580.md

latest6.4 KB
Original Source

PivotField.SortType Property

Gets or sets the type of sort to apply to the PivotTable field.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
PivotFieldSortType SortType { get; set; }
vb
Property SortType As PivotFieldSortType

Property Value

TypeDescription
PivotFieldSortType

One of the PivotFieldSortType enumeration values specifying the sort order.

|

Available values:

NameDescription
Ascending

Sorts the field in ascending order.

| | Descending |

Sorts the field in descending order.

| | Manual |

Enables manual sorting of field items by dragging them in the UI.

Currently, the SpreadsheetControl doesn’t support manual sorting of field items.

|

Remarks

Use the SortType property to sort item labels in a specific row, column or page field in a PivotTable report in ascending or descending order. Sort options are available using the PivotField.Sort property.

The following example sorts items of the “Product” field in ascending order.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["Product"];
// Sort items in the "Product" field. 
field.SortType = PivotFieldSortType.Ascending;
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Access the pivot field by its name in the collection.
Dim field As PivotField = pivotTable.Fields("Product")
' Sort items in the "Product" field. 
field.SortType = PivotFieldSortType.Ascending

You can also sort a row or column field based on values in a data field. To do this, use the PivotField.SortItems method.

The following code snippets (auto-collected from DevExpress Examples) contain references to the SortType 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-spreadsheet-pivot-table-api-examples/CS/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotFieldActions.cs#L112

csharp
// Sort items in the "Product" field.
field.SortType = PivotFieldSortType.Ascending;
#endregion #SortFieldItems

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldActions.cs#L111

csharp
// Sort items in the "Product" field.
field.SortType = PivotFieldSortType.Ascending;
#endregion #SortFieldItems

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldActions.cs#L123

csharp
// Sort items in the "Product" field.
field.SortType = PivotFieldSortType.Ascending;
#endregion #SortFieldItems

wpf-spreadsheet-pivot-table-api-examples/VB/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotFieldActions.vb#L107

vb
' Sort items in the "Product" field.
            field.SortType = PivotFieldSortType.Ascending
' #End Region ' #SortFieldItems

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldActions.vb#L106

vb
' Sort items in the "Product" field.
            field.SortType = PivotFieldSortType.Ascending
' #End Region ' #SortFieldItems

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldActions.vb#L114

vb
' Sort items in the "Product" field.
            field.SortType = PivotFieldSortType.Ascending
#End Region ' #SortFieldItems

See Also

Sort

SortItems

PivotField Interface

PivotField Members

DevExpress.Spreadsheet Namespace