Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

DxPivotGridField.DataTemplate Property

Specifies the template used to display data cells.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

#Declaration

C#
[Parameter]
public RenderFragment<object> DataTemplate { get; set; }

#Property Value

Type Description
RenderFragment<Object>

The template content.

#Remarks

The DxPivotGrid component allows you to use native Razor markup to define custom templates for its elements. Use the template’s context parameter to get the field value.

The following code snippet sets templates for the following Pivot Grid Fields:

  • Count - Uses a DataTemplate to apply bold formatting to all values.
  • Amount - Uses a DataTemplate to apply conditional formatting to values.
razor
<DxPivotGrid Data="@GridData" ShowGrandTotals="@ShowGrandTotals" ShowFieldHeaders="@ShowFieldHeaders">
    <DxPivotGridField Field="@nameof(SaleInfo.Amount)" Area="PivotGridFieldArea.Data" SummaryType="PivotGridSummaryType.Sum">
        <DataTemplate>
            <span class="@((decimal)context > 100000 ? "text-success" : "text-danger")">
                @string.Format("{0:c0}", context)
            </span>
        </DataTemplate>
    </DxPivotGridField>
    <DxPivotGridField Field="@nameof(SaleInfo.OrderId)" Caption="Count" Area="PivotGridFieldArea.Data" SummaryType="PivotGridSummaryType.Count">
        <DataTemplate>
            <span class="font-weight-bold">@context</span>
        </DataTemplate>
    </DxPivotGridField>
</DxPivotGrid>

Use the HeaderTemplate to customize content in row and column headers.

Run Demo: Pivot Grid - Pivot Grid Templates

See Also