How to get the value of grid Foreign column when exporting to PDF? For example OrderID must be displayed as OrderName after exporting to PDF.<GridColumns> <GridForeignColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" ForeignKeyValue="OrderName" TextAlign="TextAlign.Right" Width="120"></GridColumn> <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> </GridColumns>
Hi Belle Perez,
Greetings from Syncfusion support.
Query: “How to get the value of grid Foreign column when exporting to PDF? For example OrderID must be displayed as OrderName after exporting to PDF.”
We have checked your query and we suspect that you need to customize the grid header after it is exported. We would like to inform that we can customize PdfHeaderQueryCellInfoHandler to customize the Grid header. Here we have customized the header cell value inside PdfHeaderQueryCellInfoHandler. Kindly check the attached code snippet and sample for your reference.
|
<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders" AllowFiltering="true" AllowSorting="true" Toolbar="@(new List<string>() { "ExcelExport", "PdfExport" })" AllowPdfExport="true" AllowExcelExport="true" AllowPaging="true"> <GridEvents OnToolbarClick="ToolbarClickHandler" PdfHeaderQueryCellInfoEvent="PdfHeaderQueryCellInfoHandler" TValue="Order"></GridEvents> <GridColumns> <GridForeignColumn Field=@nameof(Order.EmployeeID) HeaderText="EmployeeName" ForeignKeyValue="FirstName" ForeignDataSource="@Employees" Width="150"></GridForeignColumn> </GridColumns> </SfGrid>
@code{ private SfGrid<Order> DefaultGrid;
public List<Order> Orders { get; set; } public List<EmployeeData> Employees { get; set; }
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname { await this.DefaultGrid.ExcelExport(); } else if (args.Item.Id == "Grid_pdfexport") { await this.DefaultGrid.ExportToPdfAsync(); } } public void PdfHeaderQueryCellInfoHandler(PdfHeaderQueryCellInfoEventArgs args) { if (args.Cell.Value == "EmployeeName") { args.Cell.Value = args.Column.ForeignKeyValue; } }
} |
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/DataGrid_Server-1669336876.zip
If the reported issue is not resolved then kindly share the below details to validate further from our end.
The above-requested details will be very helpful for us to validate the reported query at our end and provide the solution as early as possible.
Regards,
Monisha