Blazor Grid PDF and Excel export include aggregates
Is it possible for the blazor grid component to export the aggregate columns to PDF and Excel,when I manually add the columns to display and the data source?
I'm using Syncfusion.Blazor.Grid (19.3.0.57)
List<GridColumn> columns = new List<GridColumn>();
columns.Add(new GridColumn() { Field = "Cliente", Width = "270px", HeaderText = "Cliente", HeaderTextAlign = TextAlign.Left, TextAlign = TextAlign.Left }); //adding additional column columns.Add(new GridColumn() { Field = "Factura", AutoFit = true, HeaderText = "Factura", HeaderTextAlign = TextAlign.Left, TextAlign = TextAlign.Left }); //adding additional column columns.Add(new GridColumn() { Field = "Fecha", Width = "200px", HeaderText = "Fecha", HeaderTextAlign = TextAlign.Center, TextAlign = TextAlign.Center }); //adding additional column columns.Add(new GridColumn() { Field = "TotalFactura", HeaderText = "Total factura", HeaderTextAlign = TextAlign.Right, TextAlign = TextAlign.Right }); //adding additional column columns.Add(new GridColumn() { Field = "PendientePago", HeaderText = "Pendiente pago", HeaderTextAlign = TextAlign.Right, TextAlign = TextAlign.Right }); columns.Add(new GridColumn() { Field = "Concepto", AutoFit = true, HeaderText = "Concepto", HeaderTextAlign = TextAlign.Left, TextAlign = TextAlign.Left }); //adding additional column PdfExportProperties PdfProperties = new PdfExportProperties(); PdfProperties.DataSource = ListaImpagosrTmp; PdfProperties.PageOrientation = PageOrientation.Landscape; PdfProperties.Header = Header; PdfProperties.Footer = Footer; PdfProperties.IsRepeatHeader = true; PdfProperties.Theme = Theme; PdfProperties.FileName = titulo + ".pdf"; PdfProperties.Columns = columns; await gridImpagos.PdfExport(PdfProperties);
Grid:
Pdf document:
Excel document:
Thank you very much
|
<SfGrid DataSource="@Orders" ID="OrdersGrid" @ref="ordersGrid" AllowPaging="true" AllowSorting="true"
Toolbar="@(new List<string>() { "ExcelExport", "PdfExport" })" AllowExcelExport="true" AllowPdfExport="true">
<GridEvents ExcelAggregateTemplateInfo="ExcelAggregateTemplateInfoHandler"
PdfAggregateTemplateInfo="PdfAggregateTemplateInfoHandler" OnToolbarClick="ToolbarClickHandler" TValue="Order"></GridEvents>
<GridAggregates>
<GridAggregate>
<GridAggregateColumns>
<GridAggregateColumn Field="@nameof(Order.Freight)" Type="AggregateType.Sum" Format="C2">
<FooterTemplate>
@{
var aggregate = (context as AggregateTemplateContext);
<div>
<p>Sum: @aggregate.Sum</p>
</div>
}
</FooterTemplate>
</GridAggregateColumn>
</GridAggregateColumns>
</GridAggregate>
</GridAggregates>
<GridColumns>
...
</GridColumns>
</SfGrid>
@code {
public List<Order> Orders { get; set; }
public SfGrid<Order> ordersGrid;
public async Task ToolbarClickHandler(ClickEventArgs args)
{
if (args.Item.Id == "OrdersGrid_excelexport")
{
var columns = await ordersGrid.GetColumns(); //get the columns available in Grid
columns.Add(new GridColumn() { Field = "OrderDate" }); //adding additional column
ExcelExportProperties excelProperties = new() { FileName = "SomeFile.xlsx" };
await ordersGrid.ExcelExport(excelProperties);
}
else if (args.Item.Id == "OrdersGrid_pdfexport")
{
var columns = await ordersGrid.GetColumns();
PdfExportProperties pdfProperties = new() { FileName = "SomeFile.pdf" };
columns.Add(new GridColumn() { Field = "OrderDate" }); //adding additional column
pdfProperties.Columns = columns;
await ordersGrid.PdfExport(pdfProperties);
}
}
public void ExcelAggregateTemplateInfoHandler(ExcelAggregateEventArgs args)
{
if (args.Column.Field == "Freight")
{
args.Cell.Value = ""; //customize the aggregate cell value here
}
// Here you can customize your code
}
public void PdfAggregateTemplateInfoHandler(PdfAggregateEventArgs args)
{
// Here you can customize your code
if (args.Column.Field == "Freight")
{
args.Cell.Value = ""; //customize the aggregate cell value here
}
}
} |
In the example you do not use pdfProperties.DataSource. When I pass a list to DataSource:
var columns = await ordersGrid.GetColumns();
PdfExportProperties pdfProperties = new() { FileName = "SomeFile.pdf" };
columns.Add(new GridColumn() { Field = "OrderDate" }); //adding additional column
pdfProperties.Columns = columns;
pdfProperties.DataSource = Orders.OrderBy(p => p.Freight).ToList();
await ordersGrid.PdfExport(pdfProperties);
I get the following error:
Object reference not set to an instance of an object
Hi Gerardo,
Sorry for the inconvenience caused.
Due to some unforeseen circumstances, we could not able to
include the fix for the issue “Exception throws on exporting pdf and
excel with datasource property” in our mentioned weekly release
But we will fix this issue and this will be included in our upcoming bi-weekly
release which is expected to be rolled out on or before 20th
April,
2022.
You can now track the current status of your request, review
the proposed resolution timeline, and contact us for any further inquiries
through this link.
We will update you once the release is rolled out. Until then we appreciate your patience.
Regards,
Monisha
Hi Gerardo,
We are glad to announce that, we have included fix for the issue “Exception throws on exporting pdf and excel with datasource property” in our release(20.1.0.50). So please upgrade to our latest version of Syncfusion NuGet package to resolve the reported issue. Please find the Nuget package for latest fixes and features from below.
Nuget : https://www.nuget.org/packages/Syncfusion.Blazor.Grid
We thank you for your support and appreciate your patience in waiting for this release. Please get in touch with us if you would require any further assistance.
Regards,
Monisha
- 6 Replies
- 2 Participants
-
GL Gerardo Lopez Ruiz
- Feb 24, 2022 02:30 PM UTC
- Apr 20, 2022 01:52 PM UTC