Skip to main content
All docs
V24.2

Get Started with Blazor Pivot Table

  • 5 minutes to read

This topic describes how to create a new project or configure an existing project to use a DevExpress Pivot Table component.

Create a New Project (DevExpress Templates)

Follow our New Blazor Project tutorial to create a Blazor application based on DevExpress project templates. To add Pivot Table resources to the application, set the Add Pivot Table Resources option to true on the Settings tab.

Project Wizard - Settings

Configure an Existing Project

Follow the steps below to incorporate a Pivot Table into an existing Blazor app.

1. Register Common DevExpress Resources

Install the DevExpress.Blazor NuGet package and register DevExpress resources used for all DevExpress Blazor components.

Read Tutorial: Create a Project

Read Tutorial: Register DevExpress Blazor Resources

2. Register Pivot Table Resources

  1. Install the DevExpress.Blazor.PivotTable and DevExpress.PivotGrid.Core NuGet packages.

    1. Select ToolsNuGet Package ManagerManage NuGet Packages for Solution.

    2. In the invoked dialog, open the Browse tab, select the DevExpress package source, and install the DevExpress.Blazor.PivotTable and DevExpress.PivotGrid.Core NuGet packages.

    The DevExpress package is automatically added as a package source to your NuGet configuration files if you use the DevExpress .NET Product Installer.

    NuGet Package Manager

  2. Register the DevExpress.Blazor.PivotTable namespace in the Components/Imports.razor file:

    @using DevExpress.Blazor.Pivot
    

Add a Pivot Table Component

Follow the steps below:

  1. Add the following markup to a .razor file: <DxPivotTable></DxPivotTable>.
  2. Enable interactive render mode. Refer to .NET 8 and .NET 9 Specifics.
  3. Bind the component to data.
  4. Configure the component as your needs dictate. For more information, review the DxPivotTable class description.
@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();
    }
}

Run the application to see the result:

Pivot Table - Overview