Excel and PDF exports are not working with the Toolbar functions of SfGrid.

Answer:

It seems you didn’t set the grid reference in the SfGrid component. Find the below code snippet and the sample to resolve your reference.

<SfGrid@ref="MainGrid_locations"DataSource="@Orders"

        ID="MainGrid_locations"

        AllowPdfExport="true"

        AllowExcelExport="true"

        Toolbar="@( new List<string>() { "ColumnChooser", "Search", "ExcelExport", "PdfExport"})">

    <GridEventsOnToolbarClick="ToolbarClickHandler"TValue="Order">GridEvents>

    <GridPageSettingsPageSize="5">GridPageSettings>

    <GridFilterSettingsType="Syncfusion.Blazor.Grids.FilterType.Menu">GridFilterSettings>

    <GridPageSettingsPageCount="1"PageSizes="true">GridPageSettings>

SfGrid>

@code{

    public SfGrid MainGrid_locations { get; set; }

//You can set async void instead of void/async Task

    publicasyncvoid ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args) {

        if (args.Item.Text == "Excel Export")

        {

            Console.WriteLine("0");

            //Since it is asynchronous function use await

            awaitthis.MainGrid_locations.ExcelExport();

        }

        if (args.Item.Text == "PDF Export")

        {

            Console.WriteLine("1");

            awaitthis.MainGrid_locations.PdfExport();

        }

}

}

You can get the sample for Excel and PDF export using Toolbar functions from here.

Loader.
Up arrow icon