Skip to main content

GridExportOptions Class

The base class for the GridXlExportOptions and GridCsvExportOptions classes. Contains common options that define how a document is exported.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v23.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public abstract class GridExportOptions

Remarks

When you export grid data, the GridExportOptions class descendant object allows you to customize the settings of the exported data and the exported document.

<DxGrid @ref="Grid"
        Data="@Data"
        ShowSearchBox="true"
        SearchText="Manager"
        ShowGroupPanel="true"
        AutoExpandAllGroupRows="true"
        GroupFooterDisplayMode="GridGroupFooterDisplayMode.IfExpanded"
        SelectionMode="GridSelectionMode.Multiple"
        SelectAllCheckboxMode="GridSelectAllCheckboxMode.AllPages"
        SizeMode="Params.SizeMode" KeyboardNavigationEnabled="true">
    <Columns>
        <DxGridSelectionColumn Width="60px" AllowSelectAll="true" />
        <DxGridDataColumn FieldName="ContactName" Width="15%" />
        <DxGridDataColumn FieldName="ContactTitle" Width="15%" />
        <DxGridDataColumn FieldName="CompanyName" Width="20%" />
        <DxGridDataColumn FieldName="Country" Width="15%" GroupIndex="0" />
        <DxGridDataColumn FieldName="FullAddress" UnboundType="GridUnboundColumnType.String" UnboundExpression="[City] + ' - ' + [PostalCode] + ' - ' + [Address]" />
    </Columns>
    <TotalSummary>
        <DxGridSummaryItem FieldName="ContactName" SummaryType="GridSummaryItemType.Count" />
    </TotalSummary>
    <GroupSummary>
        <DxGridSummaryItem FieldName="ContactName" SummaryType="GridSummaryItemType.Count" FooterColumnName="ContactName" />
    </GroupSummary>
    <ToolbarTemplate>
        <DxToolbar>
            <DxToolbarItem Text="Export to XLSX" Click="ExportXlsx_Click" />
            <DxToolbarItem Text="Export to XLS" Click="ExportXls_Click" />
            <DxToolbarItem Text="Export to CSV" Click="ExportCsv_Click" />
            <DxToolbarItem Context="itemCtx" Alignment="ToolbarItemAlignment.Right">
                <Template>
                    <DxCheckBox @bind-Checked="@ExportSelectedRowsOnly">Export Selected Rows Only</DxCheckBox>
                </Template>
            </DxToolbarItem>
        </DxToolbar>
    </ToolbarTemplate>
</DxGrid>

@code {
    IEnumerable<object> Data { get; set; }
    IGrid Grid { get; set; }
    bool ExportSelectedRowsOnly { get; set; }

    protected override async Task OnInitializedAsync() {
        Data = await NwindDataService.GetCustomersAsync();
    }
    async Task ExportXlsx_Click() {
        await Grid.ExportToXlsxAsync("ExportResult", new GridXlExportOptions() {
            ExportSelectedRowsOnly = ExportSelectedRowsOnly,
            CustomizeCell = OnCustomizeCell
        });
    }
    async Task ExportXls_Click() {
        await Grid.ExportToXlsAsync("ExportResult", new GridXlExportOptions() {
            ExportSelectedRowsOnly = ExportSelectedRowsOnly,
            CustomizeCell = OnCustomizeCell
        });
    }
    async Task ExportCsv_Click() {
        await Grid.ExportToCsvAsync("ExportResult", new GridCsvExportOptions() {
            ExportSelectedRowsOnly = ExportSelectedRowsOnly
        });
    }
    void OnCustomizeCell (GridExportCustomizeCellEventArgs args) {
        if(args.ColumnFieldName == "ContactName" && args.AreaType == SheetAreaType.DataArea)
            args.Formatting.Font = new XlCellFont() { Italic = true };
        args.Handled = true;
    }
}

For more information about data export in the Grid component, refer to the following topic: Export Data in Blazor Grid.

Inheritance

See Also