Blazor Grid CSV Export not working
I upgraded to latest v48 Syncfusion and new .NET Core 5.0.0 release this morning.
Created this page to test the export features of grid and the CSV is not exporting. The command is executing but nothing is showing up at the bottom of my Chrome browser window like the Excel and PDF exports do. Note, Excel and PDF exporting is working fine.
```
@page "/"
@using Syncfusion.Blazor.Grids
@using Syncfusion.Blazor.Navigations
<div class="col-lg-12 control-section">
<div class="content-wrapper">
<div class="row">
<SfGrid ID="Grid" @ref="Grid" DataSource="@GridData" AllowPaging="true"
Toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport" })"
AllowExcelExport="true" AllowPdfExport="true">
<GridEvents OnToolbarClick="ToolbarClick" TValue="OrdersDetails"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
</div>
</div>
</div>
@code{
public class OrdersDetails
{
public string OrderID { get; set; }
public string CustomerID { get; set; }
public string Freight { get; set; }
public string ShipCountry { get; set; }
}
SfGrid<OrdersDetails> Grid;
public List<OrdersDetails> GridData { get; set; } = new List<OrdersDetails>();
protected override void OnInitialized()
{
GridData.Add(new OrdersDetails { CustomerID = "cust1", Freight = "Postal", OrderID = "33", ShipCountry = "USA" });
GridData.Add(new OrdersDetails { CustomerID = "cust2", Freight = "UPS", OrderID = "35", ShipCountry = "BRAZIL" });
GridData.Add(new OrdersDetails { CustomerID = "cust3", Freight = "FEDEX", OrderID = "37", ShipCountry = "CANADA" });
GridData.Add(new OrdersDetails { CustomerID = "cust4", Freight = "Postal", OrderID = "99", ShipCountry = "USA" });
}
public void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
{
if (args.Item.Id == "Grid_pdfexport")
{
this.Grid.PdfExport();
}
if (args.Item.Id == "Grid_excelexport")
{
this.Grid.ExcelExport();
}
if (args.Item.Id == "Grid_csvexport")
{
this.Grid.CsvExport();
}
}
}
```
SIGN IN To post a reply.
5 Replies
1 reply marked as answer
RN
Rahul Narayanasamy
Syncfusion Team
November 12, 2020 01:17 PM UTC
Hi Scott,
Greetings from Syncfusion.
Query: Blazor Grid CSV Export not working
We have validated your query and we are able to reproduce the reported problem while using the provided code snippets. You have provided Fomat property as C2 in string column which is the cause of the problem. You can resolve the problem by removing the Format property in string column(Freight). Find the below code snippets for your reference.
|
<SfGrid ID="Grid" @ref="Grid" DataSource="@GridData" AllowPaging="true"
Toolbar="@(new List<string>() { "ExcelExport", "CsvExport", "PdfExport" })"
AllowExcelExport="true" AllowPdfExport="true">
<GridEvents OnToolbarClick="ToolbarClick" TValue="OrdersDetails"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(OrdersDetails.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn>
<GridColumn Field=@nameof(OrdersDetails.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> // remove this Format property to resolve the problem
<GridColumn Field=@nameof(OrdersDetails.ShipCountry) HeaderText="Ship Country" Width="150"></GridColumn>
</GridColumns>
</SfGrid> |
Please let us know if you have any concerns.
Regards,
Rahul
SP
Scott Peal
November 12, 2020 07:49 PM UTC
How do we do an export if we want a C2 format?
BTW, I am pretty sure I just copied the code from your demo page or doc page for grid export.
RN
Rahul Narayanasamy
Syncfusion Team
November 13, 2020 08:42 AM UTC
Hi Scott,
Query: How do we do an export if we want a C2 format?
We have validated your query and we would like to inform you that the Format property is used to format number and date column values. Find the below documentation for your reference.
Reference:
You can export this Format property with number and date columns.
In your previously shared code you have used this Format property in string column. So the reported problem occurs. You can export with Format property with number and date column values.
Please let us know if you have any concerns.
Regards,
Rahul
Marked as answer
SP
Scott Peal
November 16, 2020 06:13 PM UTC
Thanks. I see the issue and you are correct. Appologies for the thread.
The demo didn't have the actual data population or data class shown. I re-created them incorrectly. It would help if the demo's included the data population methods shown in OnInitialize.
https://blazor.syncfusion.com/demos/datagrid/exporting?theme=bootstrap4
RN
Rahul Narayanasamy
Syncfusion Team
November 17, 2020 12:10 PM UTC
Hi Scott,
Thanks for the update.
We have created an internal task to include the datasource details in sample browser source tab itself. It will be included in any of our upcoming release. Until then we appreciate your patience.
Please let us know if you have any concerns.
Regards,
Rahul
SIGN IN To post a reply.
- 5 Replies
- 2 Participants
- Marked answer
-
SP Scott Peal
- Nov 11, 2020 05:01 PM UTC
- Nov 17, 2020 12:10 PM UTC