DxPivotTable.Fields Property
A collection of Pivot Table fields.
Namespace: DevExpress.Blazor.PivotTable
Assembly: DevExpress.Blazor.PivotTable.v25.1.dll
NuGet Package: DevExpress.Blazor.PivotTable
Declaration
[Parameter]
public RenderFragment Fields { get; set; }
Property Value
Type | Description |
---|---|
RenderFragment | A collection of Pivot Table fields (UI fragment). |
Remarks
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.
For detailed steps, see Add Fields.
Add Fields
Follow the steps below to add fields to a Pivot Table:
- Add
<Fields>...</Fields>
tags to the component markup to define theFields
collection. - Add DxPivotTableField objects to the collection. Use the Area property to specify an area where a field is displayed: Rows, Columns, Data, or Filter.
- 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();
}
}
Hierarchical Data Presentation
When you add multiple fields to the Row or Columns area of a Pivot Table, the table automatically groups related data fields into multiple levels (nested rows/columns). This hierarchical organization provides the following benefits for users:
- Drill down or roll up data from summary to detail with a single click.
- Navigate large datasets with ease.
Different Levels of a Data Field
You can bind multiple Pivot Table fields to the same source field, but set different group intervals to split data into different levels. The following example creates a Pivot Table that contains three fields bound to the Date
data source field. Field values are grouped as follows: Year → Quarter → Month
.
@rendermode InteractiveServer
<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>
<DxPivotTableField Field="@nameof(Sales.SaleInfo.Date)"
GroupInterval="@PivotTableGroupInterval.DateMonth"
Area="@PivotTableArea.Column"
AreaIndex="1"
Caption="Month" />
@*...*@
</Fields>
</DxPivotTable>
Master-Detail Relationships
When your dataset includes multiple related tables, a Pivot Table can bring them together into a single view and allows users to explore their hierarchical structure. The following Pivot Table combines data and constructs a hierarchy for Orders
, OrderDetails
, Products
, and Categories
data tables.
@inject IDbContextFactory<NorthwindContext> NorthwindContextFactory
@implements IDisposable
@using DevExpress.Blazor.PivotTable
<DxPivotTable Data="Data">
<Fields>
<DxPivotTableField Field="CategoryName"
Area="@PivotTableArea.Row" />
<DxPivotTableField Field="ProductName"
Area="@PivotTableArea.Row" />
<DxPivotTableField Field="OrderDate"
Area="@PivotTableArea.Column"
GroupInterval="@PivotTableGroupInterval.DateYear"
Caption="Year" />
<DxPivotTableField Field="OrderDate"
Area="@PivotTableArea.Column"
GroupInterval="@PivotTableGroupInterval.DateQuarter"
Caption="Quarter">
<ValueTemplate>
<span>@($"Q{context.Text}")</span>
</ValueTemplate>
</DxPivotTableField>
<DxPivotTableField Field="UnitPrice"
Area="@PivotTableArea.Data"
SummaryType="@PivotTableSummaryType.Sum" />
<DxPivotTableField Field="ShipCountry"
Area="@PivotTableArea.Filter" />
<DxPivotTableField Field="ShipCity"
Area="@PivotTableArea.Filter" />
</Fields>
</DxPivotTable>
@code {
NorthwindContext Northwind { get; set; }
IEnumerable<object> Data { get; set; }
protected override async Task OnInitializedAsync() {
Northwind = NorthwindContextFactory.CreateDbContext();
var products = await Northwind.Products.ToListAsync();
var categories = await Northwind.Categories.ToListAsync();
var orders = await Northwind.Orders.ToListAsync();
var orderDetails = await Northwind.OrderDetails.ToListAsync();
Data = (from c in categories
join p in products on c.CategoryId equals p.CategoryId
join od in orderDetails on p.ProductId equals od.ProductId
select new {
CategoryName = c.CategoryName,
ProductName = p.ProductName,
UnitPrice = p.UnitPrice,
OrderDate = od.Order.OrderDate,
ShipCountry = od.Order.ShipCountry,
ShipCity = od.Order.ShipCity
})
.ToList();
}
public void Dispose() {
Northwind?.Dispose();
}
}
Field Customization in the UI
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.
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
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.
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();
}
}