<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="@Orders" AllowExcelExport="true" AllowPaging="true"
Toolbar="@(new List<string>() { "ExcelExport" })" AllowSelection="true">
<GridEvents OnToolbarClick="OnToolbarClick" TValue="Order"></GridEvents>
<GridSelectionSettings Type="SelectionType.Multiple"></GridSelectionSettings>
<GridColumns>
. . .
</GridColumns>
</SfGrid>
@code{
private SfGrid<Order> DefaultGrid;
public List<Order> Orders { get; set; }
public async Task OnToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties ExcelProperties = new ExcelExportProperties();
var selected = await DefaultGrid.GetSelectedRecords();
if(selected.Count() > 0)
{
ExcelProperties.DataSource = selected; //provided selected data to Excelproperties DataSource
}
else
{
ExcelProperties.DataSource = Orders; //if there is no selected records, then provided Whole Grid datasource
}
await this.DefaultGrid.ExcelExport(ExcelProperties);
}
}
. . .
} |