I tried to export to Excel. Done and copied Method from example to my project.
By debugging shows me that all records are collected. But the export will not been done.
Here is my code.
Thanks in advice:
@page "/Test/"
@using Syncfusion.Blazor.Grids
@using Syncfusion.ExcelExport
@using System.Data
@using System.IO
@inject ILagerNur100Service lagerNur100Service
<h3>Lagerbestand Nur 100</h3>
@if (response.Success == false)
{
<div class="alert alert-danger">
<h4>@response.Message</h4>
</div>
}
@if (Artikels == null)
{
<div class="alert alert-info">
<h4>Lade Daten...</h4>
</div>
}
else
{
<br />
<SfGrid ID="Grid" @ref="DefaultGrid" DataSource="Artikels" AllowPaging="true" AllowFiltering="true" Height="800px" AllowSorting="true" Toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport" })" AllowExcelExport="true" AllowPdfExport="true">
<GridEvents OnToolbarClick="ToolbarClickHandler" TValue="LagerNur100ReadOnlyDto"></GridEvents>
<GridPageSettings PageSize="20" ></GridPageSettings>
<GridColumns >
<GridColumn Field=@nameof(LagerNur100ReadOnlyDto.Id) HeaderText="LfnNr." TextAlign="TextAlign.Left" Width="50" AllowFiltering=false Type="Syncfusion.Blazor.Grids.ColumnType.String"></GridColumn>
<GridColumn Field=@nameof(LagerNur100ReadOnlyDto.Bez) HeaderText="Bezeichnung" TextAlign="TextAlign.Right" Width="300" Type="Syncfusion.Blazor.Grids.ColumnType.String"></GridColumn>
<GridColumn Field=@nameof(LagerNur100ReadOnlyDto.Bez2) HeaderText="Bezeichnung 2" TextAlign="TextAlign.Center" Width="300" Type="Syncfusion.Blazor.Grids.ColumnType.String"></GridColumn>
<GridColumn Field=@nameof(LagerNur100ReadOnlyDto.Lb) HeaderText="Lagerbestand" TextAlign="TextAlign.Right" Width="100" Type="Syncfusion.Blazor.Grids.ColumnType.String">
<Template>
@{
var lbValue = context as LagerNur100ReadOnlyDto;
if (lbValue != null && !string.IsNullOrWhiteSpace(lbValue.Lb) && decimal.TryParse(lbValue.Lb, out decimal lbDecimal) && lbDecimal > 0)
{
@lbDecimal
}
else
{
<text>-auf Anfrage-</text>
}
}
</Template>
</GridColumn>
<GridColumn Field=@nameof(LagerNur100ReadOnlyDto.TeileGruppen) HeaderText="Teilegruppen" TextAlign="TextAlign.Right" Width="300" Type="Syncfusion.Blazor.Grids.ColumnType.String"></GridColumn>
</GridColumns>
</SfGrid>
}
@code {
private List<LagerNur100ReadOnlyDto> Artikels;
public SfGrid<LagerNur100ReadOnlyDto> DefaultGrid;
private Response<List<LagerNur100ReadOnlyDto>> response = new Response<List<LagerNur100ReadOnlyDto>> { Success = true };
public List<string> ToolbarItems = new List<string>() { "Search" };
protected override async Task OnInitializedAsync()
{
var response = await lagerNur100Service.GetLagerNur100();
if (response.Success)
{
Artikels = response.Data;
}
}
public async Task ToolbarClickHandler(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "Grid_excelexport") //Id is combination of Grid's ID and itemname
{
ExcelExportProperties ExcelProperties = new ExcelExportProperties();
ExcelProperties.ExportType = ExportType.AllPages;
ExcelProperties.FileName = "FluroLagerBestand.xlsx";
await this.DefaultGrid.ExcelExport(ExcelProperties);
}
}
}
Hi Dieter,
Greetings from Syncfusion.
We have checked your shared code snippet, and we suspect that the reported issue is due to the absence of Scripts at your end. Kindly ensure whether you have referred scripts at your application.
Please refer the below attached code snippet for script reference at your end.
[Host.cshtml /Layout.cshtml] // [Index.html]
|
@page "/" @using Microsoft.AspNetCore.Components.Web @namespace BlazorApp10_4_1_.Pages @addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <base rel='nofollow' href="~/" /> <link rel="stylesheet" rel='nofollow' href="css/bootstrap/bootstrap.min.css" /> <link rel='nofollow' href="css/site.css" rel="stylesheet" /> <link rel='nofollow' href="BlazorApp10_4(1).styles.css" rel="stylesheet" /> <link rel="icon" type="image/png" rel='nofollow' href="favicon.png"/> <script src="~/javascript.js"></script> <link rel='nofollow' href=https://cdn.syncfusion.com/blazor/24.1.47/styles/bootstrap5.css rel="stylesheet" /> <script src=https://cdn.syncfusion.com/blazor/24.1.47/syncfusion-blazor.min.js type="text/javascript"></script>
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered" /> </head>s <body> <component type="typeof(App)" render-mode="ServerPrerendered" />
<div id="blazor-error-ui"> <environment include="Staging,Production"> An error has occurred. This application may no longer respond until reloaded. </environment> <environment include="Development"> An unhandled exception has occurred. See browser dev tools for details. </environment> <a rel='nofollow' href="" class="reload">Reload</a> <a class="dismiss">🗙</a> </div>
<script src="_framework/blazor.server.js"></script> </body> </html>
|
Additional reference:
If you are facing issue after referring scripts, then kindly share us the way you have referred scripts at your end along with the syncfusion Nugets installed. So that it would be very helpful for us to validate the reported issue further at our end.
Regards,
Monisha