Skip to content

Commit 02098df

Browse files
committed
included all details view
1 parent 179dfc6 commit 02098df

File tree

3 files changed

+51
-13
lines changed

3 files changed

+51
-13
lines changed
131 KB
Loading
130 KB
Loading

MAUI/DataGrid/export-to-pdf.md

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,41 @@ private void PdfExport_CellExporting(object sender, DataGridCellPdfExportingEven
11481148

11491149
### Exporting DetailsView
11501150

1151+
By default, [DetailsViewDataGrid](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DetailsViewDataGrid.html) will not be exported to PDF. You can export `DetailsViewDataGrid` by setting `CanExportDetailsView` property as true.
1152+
1153+
```csharp
1154+
MemoryStream stream = new MemoryStream();
1155+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1156+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1157+
option.CanExportDetailsView = true;
1158+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1159+
pdfDoc.Save(stream);
1160+
pdfDoc.Close(true);
1161+
SaveService saveService = new();
1162+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1163+
```
1164+
<img src="Images/export-to-pdf/maui-datagrid-exportdetailsview.png" alt="Maui DataGrid displays Nested dataGrid exported to PDF" width="404"/>
1165+
1166+
By default, only expanded DetailsViewDataGrids only will be exported to PDF document. If you want to export all the DetailsViewDataGrids, you need to set `CanExportAllDetails` as true.
1167+
1168+
```csharp
1169+
MemoryStream stream = new MemoryStream();
1170+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1171+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1172+
option.CanExportDetailsView = true;
1173+
option.CanExportAllDetails = true;
1174+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1175+
pdfDoc.Save(stream);
1176+
pdfDoc.Close(true);
1177+
SaveService saveService = new();
1178+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
1179+
```
1180+
<img src="Images\export-to-pdf\maui-datagrid-exportalldetails.png" alt="Nested dataGrid exported to PDF" width="404"/>
1181+
1182+
Here, first record only expanded in SfDataGrid. But all the DetailsViewDataGrid’s are shown in exported PDF document.
1183+
1184+
You can customize its exporting operation by using `DataGridChildPdfExportingEventArgs`.
1185+
11511186
By default, [DetailsViewDataGrid](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.DetailsViewDataGrid.html) will be exported to PDF. You can customize its exporting operation by using `DataGridChildPdfExportingEventArgs`.
11521187

11531188
## Excluding DetailsViewDataGrid while exporting
@@ -1181,28 +1216,31 @@ private void PdfExport_DataGridChildPdfExporting(object? sender, DataGridChildPd
11811216
Here, `DetailsViewDataGrid` is not exported for the parent record having OrderID as 1002.
11821217

11831218
## Customizing DetailsViewDataGrid cells
1184-
Like parent DataGrid, you can customize the DetailsViewDataGrid cells also by using [DataGridCellPdfExportingEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridCellPdfExportingEventArgs.html).
1219+
Like parent DataGrid, you can customize the DetailsViewDataGrid cells also by using [DataGridCellPdfExportingEventArgs](https://help.syncfusion.com/cr/maui/Syncfusion.Maui.DataGrid.Exporting.DataGridCellPdfExportingEventArgs.html).Based on `DataGridCellPdfExportingEventArgs.DetailsViewDefinition` property, you can identify the particular DetailsViewDataGrid and customize it.
11851220

11861221
```csharp
11871222
private void Button_Clicked_1(object sender, EventArgs e)
11881223
{
1189-
DataGridExcelExportingController excelExport = new DataGridExcelExportingController();
1190-
DataGridExcelExportingOption option = new DataGridExcelExportingOption();
1191-
excelExport.CellExporting += ExcelExport_CellExporting;
1192-
option.CanExportDetailsView= true;
1193-
var excelEngine = excelExport.ExportToExcel(this.dataGrid, option);
1194-
var workbook = excelEngine.Excel.Workbooks[0];
11951224
MemoryStream stream = new MemoryStream();
1196-
workbook.SaveAs(stream);
1197-
workbook.Close();
1198-
excelEngine.Dispose();
1199-
string OutputFilename = "ExportFeature.xlsx";
1225+
DataGridPdfExportingController pdfExport = new DataGridPdfExportingController();
1226+
DataGridPdfExportingOption option = new DataGridPdfExportingOption();
1227+
pdfExport.DataGridChildPdfExporting += PdfExport_DataGridChildPdfExporting;
1228+
pdfExport.CellExporting += PdfExport_CellExporting;
1229+
option.CanExportDetailsView = true;
1230+
var pdfDoc = pdfExport.ExportToPdf(this.dataGrid, option);
1231+
pdfDoc.Save(stream);
1232+
pdfDoc.Close(true);
12001233
SaveService saveService = new();
1201-
saveService.SaveAndView(OutputFilename, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", stream);
1234+
saveService.SaveAndView("ExportFeature.pdf", "application/pdf", stream);
12021235
}
12031236

12041237
private void ExcelExport_CellExporting(object? sender, DataGridCellExcelExportingEventArgs e)
12051238
{
1239+
if (e.DetailsViewDefinition == null && e.DetailsViewDefinition?.RelationalColumn != "OrdersList")
1240+
{
1241+
return;
1242+
}
1243+
12061244
if (e.ColumnName == "OrderID")
12071245
{
12081246
var cellStyle = new PdfGridCellStyle();
@@ -1212,6 +1250,6 @@ Like parent DataGrid, you can customize the DetailsViewDataGrid cells also by us
12121250
}
12131251
}
12141252
```
1215-
<img alt="Customizing DetailsViewDataGrid while exporting to Excel in DataGrid" src="Images\export-to-pdf\maui-datagrid-customize-detailsview.png" Width="404"/>
1253+
<img alt="Customizing DetailsViewDataGrid while exporting to PDF in DataGrid" src="Images\export-to-pdf\maui-datagrid-customize-detailsview.png" Width="404"/>
12161254

12171255

0 commit comments

Comments
 (0)