Skip to main content
All docs
V25.1
  • Data Presentation Basics

    • 12 minutes to read

    This topic describes Pivot Table’s main elements: areas, fields, data cells, totals/grand totals.

    Run Demo

    Areas

    The Blazor Pivot Table consists of four areas where you or your user can place database fields.

    Rows Area
    Field headers allow users to re-arrange fields and sort or filter data. Unique values from corresponding fields are displayed as row headers.
    Columns Area
    Field headers allow users to re-arrange fields and sort or filter data. Unique values from corresponding fields are displayed as column headers.
    Data Area
    Field headers allow users to re-arrange fields and sort or filter data. Data cells display information from these fields. Each cell value is a summary calculated against the dataset (filtered by corresponding row/column values).
    Filter Area
    Filter fields do not affect data layout. Use field headers to filter data against fields that are not used in row, column, or data areas. Refer to Filter Data for more information.

    Pivot Table Areas

    Fields

    Pivot table fields are data fields that you add to the component to summarize and analyze data.

    Suppose that you have a SaleInfo class with fields: OrderId, Region, Country, Date, Product, Amount.

    public class SaleInfo {
            public int OrderId { get; set; }
            public string Region { get; set; }
            public string Country { get; set; }  
            public DateTime Date { get; set; }
            public string Product { get; set; }
            public int Amount { get; set; }
        }
    

    You can create a Pivot Table that:

    • Shows Region and Country in Rows.
    • Shows Date (Year and Quarter) in Columns.
    • Summarizes Amount in data cells.
    • Uses Product as a filter to look data for required product.

    Pivot Table - Add Fields

    Add Fields

    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 an area where a field is displayed: Rows, Columns, Data, or Filter.
    3. Optional. Set up additional field properties: AreaIndex, Caption, SummaryType (for data fields), CellFormat (for data fields), or ValueFormat (for row/column fields).
    @rendermode InteractiveServer
    
    <DxPivotTable Data="SalesData">
        <Fields>
            <DxPivotTableField Field="@nameof(Sales.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" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.City)"
                               Area="@PivotTableArea.Filter"/>
        </Fields>
    </DxPivotTable>
    
    @code {
        IEnumerable<Sales.SaleInfo> SalesData;
        protected override async Task OnInitializedAsync() {
            SalesData = await Sales.GetSalesAsync();
        }
    }
    

    Field Customization in the UI

    Run Demo: Pivot Table - Field Customization

    The Blazor Pivot Table allows users to customize their data layout by dragging field headers between Rows, Columns, Data, and Filter areas. This capability helps users personalize the Pivot Table structure without modifying code.

    Pivot Table - Drag Fields

    The Pivot Table also includes a Field List that offers an alternative way to manage component structure:

    • Reorder fields within each area. This action modifies a field’s AreaIndex property value.
    • Move fields across different areas. This action modifies a field’s Area property value.
    • Display or hide fields. The Hidden Fields list shows hidden fields. To display a field, users must drag the field to the desired area’s field list. This action modifies a field’s Visible property value.
    • Change field sort order. When a user hovers the mouse pointer over a field name in the list, the sort glyph appears next to the field name. A user can click the glyph to change the sort order. The sort glyph and the filter menu button remain visible when users change the sort order or applies filters in the component or Field List. If a user resets the sort order and filters to their default state, the glyph and button disappear.
    • Apply field filters. When a user hovers a mouse pointer over a field name in the list, the filter menu button Pivot Table - The Filter Menu Button appears next to the field name. This button invokes the Filter Menu that allows users to select or clear the desired field values. The sort glyph and the filter menu button remain visible if a user changed the sort order or applies filters in the component or Field List. If a user resets the sort order and filters to their default state, the glyph and button disappear.
    • Defer layout update. When the corresponding checkbox is enabled, the Pivot Table layout is not updated after each customization. Instead, changes are applied only when the user clicks the Update button.

    Pivot Table - Field List

    To display the Field List, call the ShowFieldList() method. The following code adds a button that displays the Field List:

    @rendermode InteractiveServer
    
    <DxButton Text="Show Field List" Click="OnShowFieldList"/>
    
    <DxPivotTable Data="SalesData" @ref=MyPivotTable>
        <Fields>
            <DxPivotTableField Field="@nameof(Sales.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" />
            <DxPivotTableField Field="@nameof(Sales.SaleInfo.City)"
                               Area="@PivotTableArea.Filter"/>
        </Fields>
    </DxPivotTable>
    
    @code {
        IPivotTable MyPivotTable { get; set; }
        IEnumerable<Sales.SaleInfo> SalesData;
        protected override async Task OnInitializedAsync() {
            SalesData = await Sales.GetSalesAsync();
        }
        void OnShowFieldList() {
            MyPivotTable.ShowFieldList();
        }
    }
    

    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

    You can use the CellFormat property to specify the display format for data cells.

    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 field values that include nested values (Regions and Years in the example below).
    • 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

    Run Demo: Pivot Table - Totals

    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(Sales.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>