Skip to main content
All docs
V25.1
  • GridDocumentExportSummaryItemBase.FieldName Property

    Returns a field name whose values are used to calculate the summary.

    Namespace: DevExpress.Blazor

    Assembly: DevExpress.Blazor.v25.1.dll

    NuGet Package: DevExpress.Blazor

    Declaration

    public string FieldName { get; }

    Property Value

    Type Description
    String

    A field name.

    Remarks

    When exporting Grid/TreeList data to PDF, handle the CustomizeCell event to customize table cells in the output file. Use the SummaryItems property to obtain information about summaries displayed in the processed cell.

    Grid Example

    The following example customizes the text and formatting of summaries in the exported document:

    @rendermode InteractiveServer
    @using DevExpress.Drawing;
    @inject WeatherForecastService ForecastService
    
    <DxGrid @ref="Grid" Data="@forecasts">
        <Columns>
            <DxGridDataColumn Caption="Date" FieldName="Date" ExportWidth="500" />
            <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" />
            <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" />
            <DxGridDataColumn Caption="Summary" FieldName="Summary" />
        </Columns>
        <TotalSummary>
            <DxGridSummaryItem SummaryType="GridSummaryItemType.Min" FieldName="Date" />
            <DxGridSummaryItem SummaryType="GridSummaryItemType.Max" FieldName="Date" />
            <DxGridSummaryItem SummaryType="GridSummaryItemType.Min" FieldName="TemperatureC" />
            <DxGridSummaryItem SummaryType="GridSummaryItemType.Max" FieldName="TemperatureC" />
        </TotalSummary>
        <ToolbarTemplate>
            <DxToolbar>
                <DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
            </DxToolbar>
        </ToolbarTemplate>
    </DxGrid>
    
    @code {
        IGrid Grid;
        private WeatherForecast[]? forecasts;
    
        protected override async Task OnInitializedAsync() {
            forecasts = await ForecastService.GetForecastAsync(DateOnly.FromDateTime(DateTime.Now));
        }
        async Task ExportPdf_Click() {
            await Grid.ExportToPdfAsync("ExportResult", new GridPdfExportOptions() {
                CustomizeCell = OnCustomizeCell,
            });
        }
        void OnCustomizeCell(GridDocumentExportCustomizeCellEventArgs args) {
            if (args.AreaType == DocumentExportAreaType.TotalFooter ) {
                if (args.ColumnFieldName == "Date") {
                    var sum1 = args.SummaryItems[0];
                    var sum2 = args.SummaryItems[1];
                    args.Text = sum1.SummaryType + " " + sum1.FieldName + ": " + sum1.Value;
                    args.Text += "\n" + sum2.SummaryType + " " + sum2.FieldName + ": " + sum2.Value;
                }
                if (args.ColumnFieldName == "TemperatureC") {
                    args.Text = args.SummaryItems[0].Text + "°C\n" + args.SummaryItems[1].Text + "°C";
                    args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
                }
            }
            args.Handled = true;
        }
    }
    

    Blazor Grid PDF export - Customize Cells

    TreeList Example

    The following example customizes the text and formatting of summaries in the exported document:

    @rendermode InteractiveServer
    @using DevExpress.Drawing
    @inject SpaceObjectDataProvider SpaceObjectDataProvider
    
    <DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites">
        <Columns>
            <DxTreeListDataColumn FieldName="Name" />
            <DxTreeListDataColumn FieldName="TypeOfObject" Caption="Type" />
            <DxTreeListDataColumn FieldName="Mass10pow21kg" Caption="Mass, kg" DisplayFormat="N2" />
            <DxTreeListDataColumn FieldName="MeanRadiusInKM" Caption="Radius, km" DisplayFormat="N2" />
        </Columns>
        <TotalSummary>
            <DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Count" FieldName="Name" />
            <DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Min" FieldName="MeanRadiusInKM" />
            <DxTreeListSummaryItem SummaryType="TreeListSummaryItemType.Max" FieldName="MeanRadiusInKM" />
        </TotalSummary>
        <ToolbarTemplate>
            <DxToolbar>
                <DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
            </DxToolbar>
        </ToolbarTemplate>
    </DxTreeList>
    
    @code {
        ITreeList TreeList { get; set; }
        object TreeListData { get; set; }
        protected override async Task OnInitializedAsync() {
            TreeListData = SpaceObjectDataProvider.GenerateData();
        }
        async Task ExportPdf_Click() {
            await TreeList.ExportToPdfAsync("ExportResult", new TreeListPdfExportOptions() {
                CustomizeCell = OnCustomizeCell,
            });
        }
        void OnCustomizeCell(TreeListDocumentExportCustomizeCellEventArgs args) {
            if (args.AreaType == DocumentExportAreaType.TotalFooter) {
                if (args.ColumnFieldName == "Name") {
                    var sum = args.SummaryItems[0];
                    args.Text = "Total " + sum.SummaryType + " of " + sum.FieldName + "s: " + sum.Value;
                }
                if (args.ColumnFieldName == "MeanRadiusInKM") {
                    args.Text = args.SummaryItems[0].Text + " Km\n" + args.SummaryItems[1].Text + " Km";
                    args.ElementStyle.TextAlignment = DevExpress.XtraPrinting.TextAlignment.MiddleRight;
                }
            }
            args.Handled = true;
        }
    }
    

    Blazor TreeList PDF export - Customize Cells

    See Also