Blazor Syncfusion sfgrid export to Excel

59 Views Asked by At

I'm trying to Export a list from a filtered Syncfusion grid to Excel. I followed the code from an example. The code runs but nothing seems to happen. I haven't been able to solve this by looking at Syncfusion documentation or googling it. What am I missing?

<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();
    }
}

}

0

There are 0 best solutions below