Please see attached project. The grid in the project has two template columns. I need to export those two columns when the data is exported to Excel.
I can't find any documentation or examples that show to export template columns when the data source is OData v4.
Hi Scot
Greetings from Syncfusion support.
We checked your query , As per requirement we prepared sample for the export template columns to Excel in OdataV4. We attached the sample in this ticket, please refer the attached sample for your reference.
Please get back to us if you need further assistance
Regards,
Naveen Palanivel
I've seen this example, and it doesn't quite apply to the issue I am having because the cell handler is applying a static value to eah cell. Please see the example I attached with my initial message.
The grid disaplays two columns that show how many people are registered for a training and how many people attended:
This is the Blazor code that genereates those two columns:
</GridColumn>
<GridColumn HeaderText="Registered">
<Template>
@{
var et = (context as Training);
<div>@et.EmployeeTrainings.Count()</div>
}
</Template>
</GridColumn>
<GridColumn HeaderText="Attended">
<Template>
@{
var t = (context as Training);
var et = t.EmployeeTrainings.ToList();
int count = 0;
foreach (EmployeeTraining e in et) {
if (e.Attended == Attended.Yes) {
count++;
}
}
<div>@count</div>
}
</Template>
</GridColumn>
I need the Excel export to also include the numbers for Registered and Attended.
Hi Scot,
Thanks for the patience.
We have analyzed the provided sample in the first update and found that you have defined the custom columns (Template columns as normal columns) in the ExcelExportProperties which caused the reported issue. We have modified the sample (removed external column definition and handled action in ExcelQueryCellInfoHandler) to perform the export operation with template column properly in Grid.
Refer to the below code changes for your reference.
|
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) { if (args.Item.Id == "TrainingGrid_excelexport") //Id is combination of Grid's ID and itemname { ExcelExportProperties ExcelProperties = new ExcelExportProperties { FileName = "ITSS Program Data Export " + DateTime.Now.ToString("MMddyyyy") + ".xlsx", IncludeTemplateColumn = true, };
//List<GridColumn> ExportColumns = new List<GridColumn> //{ // new GridColumn() { Field = "Id", HeaderText = "Id", Width = "250" }, // new GridColumn() { Field = "Name", HeaderText = "Name", Width = "300" }, // new GridColumn() { Field = "StartDate", HeaderText = "Start Date (UTC)", Width = "120", Format = "MM/dd/yyyy h:mm tt" }, // new GridColumn() { Field = "EndDate", HeaderText = "End Date (UTC)", Width = "120", Format = "MM/dd/yyyy h:mm tt" }, // new GridColumn() { Field = "Registered", HeaderText = "Registered", Width = "60" }, // new GridColumn() { Field = "Attended", HeaderText = "Attended", Width = "60" }, //};
//ExcelProperties.Columns = ExportColumns;
await this.TrainingGrid.ExcelExport(ExcelProperties); } }
public void ExcelQueryCellInfoHandler(ExcelQueryCellInfoEventArgs<Training> args) { if (args.Column.HeaderText == "Registered") { args.Cell.Value = args.Data.EmployeeTrainings.Count(); } if (args.Column.HeaderText == "Attended") { var et = args.Data.EmployeeTrainings.ToList(); int count = 0;
foreach (EmployeeTraining e in et) { if (e.Attended == Attended.Yes) { count++; } } args.Cell.Value = count; } } |
Please find the modified sample in the attachments. Kindly get back to us if you have further queries.
Regards,
Vignesh Natarajan
Hi Scot,
Currently we are checking the reported query at our end. We will update further details on or before 21 September 2022.
Until then we appreciate your patience.
Regards,
Naveen Palanivel