我正在尝试将列表从过滤后的 Syncfusion 网格导出到 Excel。我按照示例中的代码进行操作。代码运行了,但似乎什么也没发生。我无法通过查看 Syncfusion 文档或谷歌搜索来解决这个问题。我错过了什么?
<SfGrid
ID="ExpenseGrid"
@ref=DefaultGrid
Toolbar="@(new List<string>() {"ExcelExport"})"
AllowExcelExport="true"
DataSource="@expenses"
AllowSorting="true"
AllowFiltering="true">
<GridEvents OnToolbarClick="ToolbarClickHandler" TValue="Expense"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(Expense.Item) HeaderText="Item" TextAlign="TextAlign.Center" Width="200"></GridColumn>
<GridColumn Field=@nameof(Expense.IncurDate) HeaderText="Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Center" Width="130"></GridColumn>
<GridColumn Field=@nameof(Expense.Cost) HeaderText="Cost" Format="C2" TextAlign
="TextAlign.Center" Width="150"></GridColumn>
<GridColumn Field=@nameof(Expense.Category) HeaderText="Category" TextAlign="TextAlign.Center" Width="120"></GridColumn>
<GridColumn Field=@nameof(Expense.SubCategory) HeaderText="SubCategory" TextAlign="TextAlign.Center" Width="120"></GridColumn>
</GridColumns>
</SfGrid>
@code {
private List<Expense> expenses = new();
private SfGrid<Expense> DefaultGrid;
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if(args.Item.Id == "ExpenseGrid_excelexport")
{
await this.DefaultGrid.ExportToExcelAsync();
}
}
}
ExcelExportProperties excelExportProperties = new()
{
FileName = "YourFilename.xlsx",
};
await ExpenseGrid.ExportToExcelAsync(excelExportProperties);