Back to Devexpress

GridDocumentExportOptions.SelectedRowsExportMode Property

blazor-devexpress-dot-blazor-dot-griddocumentexportoptions-c1dd5cc5.md

latest5.8 KB
Original Source

GridDocumentExportOptions.SelectedRowsExportMode Property

In ExportSelectedRowsOnly mode, specifies whether to export parent group rows.

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
[DefaultValue(GridSelectedRowsExportMode.Flat)]
public GridSelectedRowsExportMode SelectedRowsExportMode { get; set; }

Property Value

TypeDefaultDescription
GridSelectedRowsExportModeFlat

An enumeration value.

|

Available values:

NameDescription
Flat

The Grid exports selected rows as a flat list.

| | KeepGrouping |

The Grid exports selected records and corresponding group rows.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to SelectedRowsExportMode
GridExportEventArgs

.DocumentOptions .SelectedRowsExportMode

|

Remarks

Note

This property is not in effect if ExportSelectedRowsOnly is set to false (default).

When exporting Grid data to PDF, you can activate the ExportSelectedRowsOnly option. If active, the Grid component ignores group settings and exports selected rows as flat data.

Set SelectedRowsExportMode to KeepGrouping to export selected records and their parent group rows:

razor
@rendermode InteractiveServer
@using DevExpress.Drawing;
@inject WeatherForecastService ForecastService

<DxGrid @ref="Grid" Data="@forecasts" ShowGroupPanel="true">
    <Columns>
        <DxGridSelectionColumn Width="60px" AllowSelectAll="true" />
        <DxGridDataColumn Caption="Date" FieldName="Date" />
        <DxGridDataColumn Caption="Temperature (C)" FieldName="TemperatureC" />
        <DxGridDataColumn Caption="Temperature (F)" FieldName="TemperatureF" />
        <DxGridDataColumn Caption="Summary" FieldName="Summary" GroupIndex="0" />
    </Columns>
    <ToolbarTemplate>
        <DxToolbar>
            <DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
        </DxToolbar>
    </ToolbarTemplate>
</DxGrid>

@code {
    IGrid Grid;
    object forecasts;

    protected override async Task OnInitializedAsync() {
        forecasts = await ForecastService.GetForecastAsync();
    }
    async Task ExportPdf_Click() {
        await Grid.ExportToPdfAsync("ExportResult", new GridPdfExportOptions() {
            ExportSelectedRowsOnly = true,
            SelectedRowsExportMode = GridSelectedRowsExportMode.KeepGrouping
        });
    }
}
csharp
using System;

public class WeatherForecast {
    public int ID { get; set; }
    public DateTime Date { get; set; }
    public int TemperatureC { get; set; }
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    public string? Summary { get; set; }
}
csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;

public class WeatherForecastService {
    public readonly string[] Summaries = new[] {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };
    private List<WeatherForecast>? Forecasts;
    public Task<List<WeatherForecast>> GetForecastAsync() {
        if (Forecasts == null) {
            var rnd = new Random();
            Forecasts = Enumerable.Range(1, 25).Select(index => new WeatherForecast {
                ID = index,
                Date = DateTime.Today.AddDays(index),
                TemperatureC = rnd.Next(-20, 55),
                Summary = Summaries[rnd.Next(Summaries.Length)]
            }).ToList();
        }
        return Task.FromResult(Forecasts);
    }
    public Task<List<WeatherForecast>> ChangeForecastAsync(WeatherForecast changed) {
        var originalForecast = Forecasts.FirstOrDefault(i => i.ID == changed.ID);
        if (originalForecast != null) {
            originalForecast.TemperatureC = changed.TemperatureC;
            originalForecast.Summary = changed.Summary;
            originalForecast.Date = changed.Date;
        }
        else {
            Forecasts.Add(changed);
        }
        return Task.FromResult(Forecasts);
    }
    public Task<List<WeatherForecast>> Remove(WeatherForecast forecast) {
        Forecasts.Remove(forecast);
        return Task.FromResult(Forecasts);
    }
}
csharp
// ...
builder.Services.AddSingleton<WeatherForecastService>();

Read Tutorial: Export to PDF Run Demo: Export Data

See Also

GridDocumentExportOptions Class

GridDocumentExportOptions Members

DevExpress.Blazor Namespace