GridDocumentExportOptionsBase.ExportSelectedRowsOnly Property
Specifies whether the component exports only selected rows.
Namespace: DevExpress.Blazor
Assembly: DevExpress.Blazor.v25.1.dll
NuGet Package: DevExpress.Blazor
Declaration
[DefaultValue(false)]
public bool ExportSelectedRowsOnly { get; set; }
Property Value
Type | Default | Description |
---|---|---|
Boolean | false |
|
Remarks
When exporting Grid or TreeList data to PDF, enable the ExportSelectedRowsOnly
property to export selected rows only. To implement this behavior when the component is bound to a GridDevExtremeDataSource<T>, you must also specify the KeyFieldName
property.
Grid Example
Note
If ExportSelectedRowsOnly
is enabled, the Grid component ignores group settings and exports data in a flat format.
The following example exports selected Grid rows to PDF:
@rendermode InteractiveServer
@using DevExpress.Drawing;
@inject WeatherForecastService ForecastService
<DxGrid @ref="Grid" Data="@forecasts">
<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" />
</Columns>
<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() {
ExportSelectedRowsOnly = true,
});
}
}
TreeList Example
Note
If ExportSelectedRowsOnly
is enabled, the TreeList component ignores hierarchy and exports data in a flat format. When bound to a hierarchical data source, the component exports children of each selected row (even if children are unselected).
The following example exports selected TreeList rows to PDF as a flat list:
@rendermode InteractiveServer
@using DevExpress.Drawing
@inject SpaceObjectDataProvider SpaceObjectDataProvider
<DxTreeList @ref="TreeList" Data="TreeListData" ChildrenFieldName="Satellites">
<Columns>
<DxTreeListSelectionColumn Width="60px" AllowSelectAll="true" />
<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>
<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() {
ExportSelectedRowsOnly = true,
});
}
}
You can use the RowExporting event to export selected records and keep row hierarchy. Note that you need to export all parents of a selected row to display this row in the exported document (even if parents are unselected). The following example exports selected space objects and keeps hierarchy:
@rendermode InteractiveServer
@using DevExpress.Drawing
@inject SpaceObjectDataProvider SpaceObjectDataProvider
<DxTreeList @ref="TreeList"
Data="TreeListData"
ChildrenFieldName="Satellites"
@bind-SelectedDataItems="SelectedDataItems">
<Columns>
<DxTreeListSelectionColumn Width="60px" AllowSelectAll="true" />
<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>
<ToolbarTemplate>
<DxToolbar>
<DxToolbarItem Text="Export to PDF" Click="ExportPdf_Click" BeginGroup="true" />
</DxToolbar>
</ToolbarTemplate>
</DxTreeList>
@code {
ITreeList TreeList { get; set; }
object TreeListData { get; set; }
IReadOnlyList<object> SelectedDataItems { get; set; }
protected override async Task OnInitializedAsync() {
TreeListData = SpaceObjectDataProvider.GenerateData();
}
async Task ExportPdf_Click() {
await TreeList.ExportToPdfAsync("ExportResult", new TreeListPdfExportOptions() {
RowExporting = OnRowExporting,
});
}
void OnRowExporting(TreeListRowExportingEventArgs args) {
var spaceObject = (SpaceObject)args.DataItem;
if (SelectedDataItems.Contains(spaceObject))
return;
foreach(var child in spaceObject.Satellites)
if (SelectedDataItems.Contains(child))
return;
else foreach (var child2 in child!.Satellites)
if (SelectedDataItems.Contains(child2))
return;
args.Cancel = true;
}
}