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 PivotGridFieldSortCondition 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 PivotGridFieldSortBySummaryInfo.Conditions collection to specify the column by which Product Name values should be sorted. A data field that identifies the column is specified via the PivotGridFieldSortBySummaryInfo.Field property.
using System;
using System.Web.UI;
using DevExpress.XtraPivotGrid;
namespace ASPxPivotGrid_SortBySummary {
public partial class _Default : Page {
protected void ASPxPivotGrid1_Load(object sender, EventArgs e) {
// Specifies a data field whose summary values should be used to sort values
// of the Product Name field.
fieldProductName.SortBySummaryInfo.Field = fieldUnitPrice;
// Specifies a column by which the Product Name field values should be sorted.
fieldProductName.SortBySummaryInfo.Conditions.Clear();
fieldProductName.SortBySummaryInfo.Conditions.Add(
new PivotGridFieldSortCondition(fieldOrderYear, "1994"));
fieldProductName.SortBySummaryInfo.Conditions.Add(
new PivotGridFieldSortCondition(fieldOrderMonth, "9"));
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs"
Inherits="ASPxPivotGrid_SortBySummary._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v10.2, Version=10.2.6.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxPivotGrid"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="AccessDataSource1"
OnLoad="ASPxPivotGrid1_Load">
<Fields>
<dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="1"
Caption="Product Name" FieldName="ProductName" />
<dx:PivotGridField ID="fieldOrderYear" Area="ColumnArea" AreaIndex="0"
Caption="Year" FieldName="OrderDate" GroupInterval="DateYear" />
<dx:PivotGridField ID="fieldUnitPrice" Area="DataArea" AreaIndex="0"
Caption="UnitPrice" FieldName="UnitPrice" />
<dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="1"
Caption="Quantity" FieldName="Quantity" />
<dx:PivotGridField ID="fieldCategoryName" Area="RowArea" AreaIndex="0"
Caption="Category Name" FieldName="CategoryName" />
<dx:PivotGridField ID="fieldOrderMonth" Area="ColumnArea" AreaIndex="2"
Caption="Month" FieldName="OrderDate" GroupInterval="DateMonth" />
</Fields>
</dx:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/nwind.mdb"
SelectCommand="SELECT [ProductName], [CategoryName], [OrderDate],
[Quantity], [UnitPrice] FROM [SalesPerson]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
<%@ Page Language="vb" AutoEventWireup="true" CodeBehind="Default.aspx.vb"
Inherits="ASPxPivotGrid_SortBySummary._Default" %>
<%@ Register Assembly="DevExpress.Web.ASPxPivotGrid.v10.2, Version=10.2.6.0,
Culture=neutral, PublicKeyToken=b88d1754d700e49a"
Namespace="DevExpress.Web.ASPxPivotGrid"
TagPrefix="dx" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<dx:ASPxPivotGrid ID="ASPxPivotGrid1" runat="server" DataSourceID="AccessDataSource1"
OnLoad="ASPxPivotGrid1_Load">
<Fields>
<dx:PivotGridField ID="fieldProductName" Area="RowArea" AreaIndex="1"
Caption="Product Name" FieldName="ProductName" />
<dx:PivotGridField ID="fieldOrderYear" Area="ColumnArea" AreaIndex="0"
Caption="Year" FieldName="OrderDate" GroupInterval="DateYear" />
<dx:PivotGridField ID="fieldUnitPrice" Area="DataArea" AreaIndex="0"
Caption="UnitPrice" FieldName="UnitPrice" />
<dx:PivotGridField ID="fieldQuantity" Area="DataArea" AreaIndex="1"
Caption="Quantity" FieldName="Quantity" />
<dx:PivotGridField ID="fieldCategoryName" Area="RowArea" AreaIndex="0"
Caption="Category Name" FieldName="CategoryName" />
<dx:PivotGridField ID="fieldOrderMonth" Area="ColumnArea" AreaIndex="2"
Caption="Month" FieldName="OrderDate" GroupInterval="DateMonth" />
</Fields>
</dx:ASPxPivotGrid>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/nwind.mdb"
SelectCommand="SELECT [ProductName], [CategoryName], [OrderDate],
[Quantity], [UnitPrice] FROM [SalesPerson]">
</asp:AccessDataSource>
</div>
</form>
</body>
</html>
Imports Microsoft.VisualBasic
Imports System
Imports System.Web.UI
Imports DevExpress.XtraPivotGrid
Namespace ASPxPivotGrid_SortBySummary
Partial Public Class _Default
Inherits Page
Protected Sub ASPxPivotGrid1_Load(ByVal sender As Object, ByVal e As EventArgs)
' Specifies a data field whose summary values should be used to sort values
' of the Product Name field.
fieldProductName.SortBySummaryInfo.Field = fieldUnitPrice
' Specifies a column by which the Product Name field values should be sorted.
fieldProductName.SortBySummaryInfo.Conditions.Clear()
fieldProductName.SortBySummaryInfo.Conditions.Add( _
New PivotGridFieldSortCondition(fieldOrderYear, "1994"))
fieldProductName.SortBySummaryInfo.Conditions.Add( _
New PivotGridFieldSortCondition(fieldOrderMonth, "9"))
End Sub
End Class
End Namespace