Skip to main content
All docs
V24.2

DxPivotTable Class

A Pivot Table component for multi-dimensional data analysis and cross-tab reporting.

Namespace: DevExpress.Blazor.PivotTable

Assembly: DevExpress.Blazor.PivotTable.v24.2.dll

NuGet Package: DevExpress.Blazor.PivotTable

Declaration

public class DxPivotTable :
    ParameterTrackerComponent,
    IAsyncDisposable,
    INestedSettingsOwner,
    IPivotTableDataParamsAccessor,
    IVirtualScrollProviderOwner,
    IPivotTable

Remarks

Important

This component is currently available as a community technology preview (CTP) and is expected to officially ship in 2025. If you need to add Pivot Table UI to a current project, use our existing Pivot Grid component. We are developing a new version to leverage the capabilities available in the common DevExpress data engine (used across other .NET platforms).

The Pivot Table component allows you to display and analyze multi-dimensional data from an underlying data source.

Pivot Table - Overview

Run Demo

Get Started

Use the following guide to create your first project:

Read Tutorial: Get Started with Pivot Table

.NET 8 and .NET 9 Specifics

Blazor Pivot Table supports static render mode that can display static data on a single page. To use other features, enable interactivity on a Razor page and allow the Pivot component to execute scripts and display data. Refer to the following topic for additional information: Enable Interactive Render Mode.

@rendermode InteractiveServer

Bind to Data

Use the Data property to bind the Pivot Table component to a data source.

@rendermode InteractiveServer

<DxPivotTable Data="SalesData">
    <Fields>
        <DxPivotTableField Field="@nameof(SaleInfo.Region)"
                           Area="@PivotTableArea.Row"
                           AreaIndex="0" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)"
                           Area="@PivotTableArea.Row"
                           SortOrder="@PivotTableSortOrder.Descending"
                           AreaIndex="1" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateYear"
                           Area="@PivotTableArea.Column"
                           AreaIndex="0" 
                           Caption="Year" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateQuarter"
                           Area="@PivotTableArea.Column"
                           AreaIndex="1"
                           Caption="Quarter" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                           SortOrder="@PivotTableSortOrder.Ascending"
                           Area="@PivotTableArea.Data"
                           SummaryType="@PivotTableSummaryType.Sum" />
    </Fields>
</DxPivotTable>

@code {
    IEnumerable<SaleInfo> SalesData;
    protected override async Task OnInitializedAsync() {
        SalesData = await Sales.GetSalesAsync();
    }
}

Fields

DxPivotTableField objects supply data to Pivot Table areas: columns, rows, and data cells.

Pivot Table Areas

Follow the steps below to add fields to a Pivot Table:

  1. Add <Fields>...</Fields> tags to the component markup to define the Fields collection.
  2. Add DxPivotTableField objects to the collection. Use the Area property to specify the area where the field is displayed:
    • Row: The field caption is displayed as a row header. Field values are displayed as rows.
    • Column: The field caption is displayed as a column header. Field values are displayed as columns.
    • Data: The field caption is displayed in the header area. Field values are used to calculate summaries displayed in data cells.
  3. Optional. Set up additional field properties: AreaIndex, Caption, SummaryType (for data fields), and others.
@rendermode InteractiveServer

<DxPivotTable Data="SalesData">
    <Fields>
        <DxPivotTableField Field="@nameof(SaleInfo.Region)"
                           Area="@PivotTableArea.Row"
                           AreaIndex="0" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)"
                           Area="@PivotTableArea.Row"
                           SortOrder="@PivotTableSortOrder.Descending"
                           AreaIndex="1" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateYear"
                           Area="@PivotTableArea.Column"
                           AreaIndex="0" 
                           Caption="Year" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateQuarter"
                           Area="@PivotTableArea.Column"
                           AreaIndex="1"
                           Caption="Quarter" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                           SortOrder="@PivotTableSortOrder.Ascending"
                           Area="@PivotTableArea.Data"
                           SummaryType="@PivotTableSummaryType.Sum" />
    </Fields>
</DxPivotTable>

@code {
    IEnumerable<SaleInfo> SalesData;
    protected override async Task OnInitializedAsync() {
        SalesData = await Sales.GetSalesAsync();
    }
}

Data Cells, Summaries

Pivot Table data cells display summaries calculated against data fields. The field’s SummaryType specifies the aggregate function.

<DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                   SortOrder="@PivotTableSortOrder.Ascending"
                   Area="@PivotTableArea.Data"
                   SummaryType="@PivotTableSummaryType.Sum" />

Commonly used summary types are:

Summary Type Description
Sum
(the default type)
The sum of field values. This type applies to numeric fields only.
Pivot Table - The Sum summary type
Avg The average of field values. This type applies to numeric fields only.
pivot func average
Count The total number of field values.
Max The largest field value.
Min The smallest field value.
Other types

Totals, Grand Totals

The DevExpress Blazor Pivot Table calculates totals for its data and displays them as separate columns and rows. There are four types of totals:

  • Row/column totals display sub-totals calculated for outer row/column fields.
  • Row/column grand totals display overall totals calculated against all rows/columns.

Pivot Table Totals

Run Demo: Totals

You can use the following properties to change totals visibility:

The following code hides row and column grand totals:

<DxPivotTable Data="SalesData"
              ShowColumnGrandTotals="false"
              ShowRowGrandTotals="false">
    <Fields>
        @*...*@
    </Fields>
</DxPivotTable>

You can also use the following properties to set the position of row/column totals relative to rows/columns:

The following code changes the position of row and column totals to Before:

<DxPivotTable Data="SalesData"
              RowTotalsPosition="PivotTableRowTotalsPosition.Before"
              ColumnTotalsPosition="PivotTableColumnTotalsPosition.Before">
    <Fields>
        @*...*@
    </Fields>
</DxPivotTable>

Pivot Table - Totals Position

Sort Data

The Blazor Pivot Table automatically sorts values in column and row areas. A sort glyph next to a field caption indicates the sort order (ascending or descending). The default order is ascending. To set a sort order in code, use the field’s SortOrder property.

<DxPivotTable Data="SalesData" @ref="PivotTable">
    <Fields>
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)qwq"
                           Area="@PivotTableArea.Row"
                           AreaIndex="1"
                           SortOrder="@PivotTableSortOrder.Descending"/>
        @*...*@
    </Fields>
</DxPivotTable>

Click a field caption in the Pivot Table’s header area to sort data in the UI.

Pivot Table - Sort Data

Group Data

The Blazor Pivot Table automatically groups data if row or column areas include multiple fields. All groups expand on data load. You can set the AutoExpandGroups property to false to collapse groups. You can also use the ExpandAllGroups or CollapseAllGroups methods to expand/collapse all groups at runtime.

@rendermode InteractiveServer

<DxPivotTable Data="SalesData" @ref="PivotTable">
    <Fields>
        <DxPivotTableField Field="@nameof(SaleInfo.Region)"
                           Area="@PivotTableArea.Row"
                           AreaIndex="0" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)"
                           Area="@PivotTableArea.Row"
                           SortOrder="@PivotTableSortOrder.Descending"
                           AreaIndex="1" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateYear"
                           Area="@PivotTableArea.Column"
                           AreaIndex="0" 
                           Caption="Year" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateQuarter"
                           Area="@PivotTableArea.Column"
                           AreaIndex="1"
                           Caption="Quarter" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                           SortOrder="@PivotTableSortOrder.Ascending"
                           Area="@PivotTableArea.Data"
                           SummaryType="@PivotTableSummaryType.Sum" />
    </Fields>
</DxPivotTable>
<p></p>
<DxToolbar>
    <Items>
        <DxToolbarItem Text="Collapse Groups" Click="() => PivotTable.CollapseAllGroups()" />
        <DxToolbarItem Text="Expand Groups" Click="() => PivotTable.ExpandAllGroups()" />  
    </Items>
</DxToolbar>

@code {
    IPivotTable PivotTable { get; set; }
    IEnumerable<SaleInfo> SalesData;
    protected override async Task OnInitializedAsync() {
        SalesData = await Sales.GetSalesAsync();
    }
}

Pivot Table - Expand and Collapse Groups

The GroupInterval property allows you to specify how the Pivot Table groups the field values. Predefined options include Alphabetical, Numeric, and multiple date-related intervals. You can also implement a custom group logic.

<DxPivotTable Data="SalesData">
    <Fields>
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateYear"
                           Area="@PivotTableArea.Column"
                           AreaIndex="0" 
                           Caption="Year" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateQuarter"
                           Area="@PivotTableArea.Column"
                           AreaIndex="1"
                           Caption="Quarter" >
            <ValueTemplate>
                <span>@($"Q{context.Text}")</span>
            </ValueTemplate>
        </DxPivotTableField>
        @*...*@
    </Fields>
</DxPivotTable>

The following image displays two Pivot Tables:

  • The first Pivot Table contains one field bound to the Date data source field. It displays original field values as column headers.
  • The second Pivot Table contains two fields bound to the Date data source field. The field values are grouped by years and quarters (see code above).

Pivot Table - Group Data

Data Format

Use the following properties to specify display format for Pivot Table’s data:

CellFormat
Specifies the display format for data cells.
ValueFormat
Specifies the display format for field values displayed in rows or columns.

Templates

The Pivot Table component allows you to use templates to customize the appearance of its headers, field values, and data cells.

  • The following templates are available at the component level:

    FieldHeaderTemplate
    Specifies a common template to display field captions in the header area.
    FieldValueTemplate
    Specifies a common template to display field values in rows or columns.
    FieldCellTemplate
    Specifies a common template for all data cells in the Pivot Table.
  • The following templates allows you to specify templates for individual fields:

    HeaderTemplate
    Specifies a template to display the current field’s caption.
    ValueTemplate
    Specifies a template to display the current field’s values.
    CellTemplate
    Specifies a template for data cells that correspond to the current field.

The following code applies ValueTemplate and CellTemplate to individual fields:

@rendermode InteractiveServer

<DxPivotTable Data="SalesData">
    <Fields>
        <DxPivotTableField Field="@nameof(SaleInfo.Region)"
                           Area="@PivotTableArea.Row"
                           AreaIndex="0" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Country)"
                           Area="@PivotTableArea.Row"
                           SortOrder="@PivotTableSortOrder.Descending"
                           AreaIndex="1" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateYear"
                           Area="@PivotTableArea.Column"
                           AreaIndex="0" 
                           Caption="Year" />
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
                           GroupInterval="@PivotTableGroupInterval.DateQuarter"
                           Area="@PivotTableArea.Column"
                           AreaIndex="1"
                           Caption="Quarter" >
            <ValueTemplate>
                <span>@($"Q{context.Text}")</span>
            </ValueTemplate>
        </DxPivotTableField>
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                           SortOrder="@PivotTableSortOrder.Ascending"
                           Area="@PivotTableArea.Data"
                           SummaryType="@PivotTableSummaryType.Sum">
            <CellTemplate>
                <span class="fw-bold">@context.Value</span>
            </CellTemplate>
        </DxPivotTableField>
    </Fields>
</DxPivotTable>

@code {
    IEnumerable<SaleInfo> SalesData;
    protected override async Task OnInitializedAsync() {
        SalesData = await Sales.GetSalesAsync();
    }
}

Pivot Table - Templates

Run Demo: Templates

Virtual Scrolling

If the Pivot Table displays a large number of data cells, enable virtual scrolling to improve performance. Set the VirtualScrollingEnabled property to true. In this mode, the Pivot Table renders data on demand as a user scrolls through rows/columns.

<DxPivotTable Data="SalesData"
              VirtualScrollingEnabled="true">
    <Fields>
        @*...*@
    </Fields>
</DxPivotTable>

Virtual Scrolling

Run Demo

Cell Widths

The control applies the following default widths to cells:

  • Row fields, row totals, row grand totals: 200 pixels.
  • Data fields, corresponding column fields, column totals, column grand totals: 100 pixels.

Use the Width property to set cell widths for fields. The Width property behavior depends on the area where the field is located:

  • Row fields: The property sets header cell width.
  • Data fields: The property sets data cell width.
  • Column fields: If the Pivot Table does not have data fields, the property sets to column header width. Otherwise, the property has no effect.
<DxPivotTable Data="SalesData">
    <Fields>
        <DxPivotTableField Field="@nameof(SaleInfo.Region)"
                           Area="@PivotTableArea.Row"
                           AreaIndex="0" 
                           Width="100"/>
        <DxPivotTableField Field="@nameof(Sales.SaleInfo.Amount)"
                           SortOrder="@PivotTableSortOrder.Ascending"
                           Area="@PivotTableArea.Data"
                           SummaryType="@PivotTableSummaryType.Sum" 
                           Width="80"/>
        @*...*@
    </Fields>
</DxPivotTable>

Inheritance

Object
ComponentBase
DxComponentBase
DevExpress.Blazor.Internal.ParameterTrackerComponent
DxPivotTable
See Also