Blazor grid exports have blank rows

Hi, I have a project using Syncfusion.Blazor version 18.1.0.36-beta and every time I export using csv, excel or pdf I just get blank rows. I am just using the boilerplate code. I do note that I am getting the headers and the correct number of lines exported, it's just that all the fields are blank.

Here is the grid I am using.

<SfGrid ID="Grid" @ref="@Grid" TValue="SupplierFilePricing" AllowSorting="true" AllowResizing="true" AllowReordering="true" AllowGrouping="true" AllowPaging="true" Toolbar="@(new List<string>() { "Search", "Add", "Edit", "Cancel", "Delete", "ExcelExport", "CsvExport", "PdfExport" })" AllowFiltering="true" AllowSelection="true" AllowPdfExport="true" AllowExcelExport="true">
    <SfDataManager Url="/api/SupplierFilePricing" InsertUrl="/api/SupplierFilePricing/Insert" UpdateUrl="/api/SupplierFilePricing/Update" RemoveUrl="/api/SupplierFilePricing/Remove" Adaptor="Adaptors.UrlAdaptor"></SfDataManager>
    <GridPageSettings PageSize="25"></GridPageSettings>
    <GridFilterSettings Type="Syncfusion.Blazor.Grids.FilterType.Excel"></GridFilterSettings>
    <GridEditSettings AllowAdding="true" AllowDeleting="true" AllowEditing="true" Mode="EditMode.Normal"></GridEditSettings>
    <GridEvents OnToolbarClick="ToolbarClick" TValue="SupplierFilePricing"></GridEvents>
    <GridColumns>

        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.SupplierFilePricingId) HeaderText="SupplierFilePricingId" IsPrimaryKey="true" IsIdentity="true" Visible="false"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.SupplierId) HeaderText="SupplierId" Type="ColumnType.Number"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.Worksheet) HeaderText="Worksheet" Type="ColumnType.String"></GridColumn>

        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.CodeColumn) HeaderText="CodeColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.MpnColumn) HeaderText="MpnColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.NameColumn) HeaderText="NameColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.QtyColumn) HeaderText="QtyColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.ManufacturerColumn) HeaderText="ManufacturerColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.CategoryColumn) HeaderText="CategoryColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.SubCategoryColumn) HeaderText="SubCategoryColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.CostColumn) HeaderText="CostColumn" Type="ColumnType.String"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.ListPriceColumn) HeaderText="ListPriceColumn" Type="ColumnType.String"></GridColumn>

        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.MpnFromCode) HeaderText="MpnFromCode" Type="ColumnType.Boolean"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.MpnFromCodeRemoveStrings) HeaderText="MpnFromCodeRemoveStrings" Type="ColumnType.String"></GridColumn>

        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.PricingGroup) HeaderText="PricingGroup" Type="ColumnType.String"></GridColumn>

        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.LastUpdated) HeaderText="LastUpdated" Format="dd/MM/yyyy" Type="ColumnType.DateTime" EditType="EditType.DatePickerEdit"></GridColumn>
        <GridColumn Field=@nameof(ISD.SkyNet.EF.Models.SupplierFilePricing.LastProcessed) HeaderText="LastProcessed" Format="dd/MM/yyyy" Type="ColumnType.DateTime" EditType="EditType.DatePickerEdit"></GridColumn>

    </GridColumns>
</SfGrid>

Here is the C# code; 

    public void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args)
    {
        if (args.Item.Id == "Grid_excelexport")
        {
            this.Grid.ExcelExport();
        }
        if (args.Item.Id == "Grid_csvexport")
        {
            this.Grid.CsvExport();
        }
        if (args.Item.Id == "Grid_pdfexport")
        {
            this.Grid.PdfExport();
        }
    }

Any suggestions as to what I am doing wrong?

Kind regards,
Stuart


13 Replies

RS Renjith Singh Rajendran Syncfusion Team March 31, 2020 09:06 AM UTC

Hi Stuart,   
  
Thanks for contacting Syncfusion support. 
  
We suspect that you may be facing camel case problem in your application. Normally, ASP.NET Core 1.0+ framework has camel casing issues while serializing the JSON Object. If you are facing the same camel casing issue (first letter of the word will be converted to small case) while running the sample then please use the below codes in Startup.cs file to overcome that casing issue.   
  
In the below code, we have called the ContractResolver options under the Startup.cs file to avoid camel casing conversion during the serialization process. The is related to ASP.NET Core specifics and we suggest refer to the following article which describes how to overcome a similar issues.  
  
  
We have also prepared a sample to performing exporting with UrlAdaptor in Grid. Please download the sample form the link below, 
 
Also we have discussed this topic in our below documentation, 
 
Please use the code below,  
  
[Startup.cs]  
  
            public void ConfigureServices(IServiceCollection services) 
            { 
                ... 
               services.AddSyncfusionBlazor(); 
                services.AddControllers().AddNewtonsoftJson(options => 
                { 
                    options.SerializerSettings.ContractResolver = new DefaultContractResolver(); 
                }); 
                services.AddSingleton<OrderDataAccessLayer>(); 
            } 
  
   
Kindly get back to us if you have any queries.   
  
Regards,  
Renjith Singh Rajendran. 



ST Stuart March 31, 2020 07:56 PM UTC

Hi Renjith,

Thanks for that clue. I'm using the new .Net Core 3.1 builtin Json handler so the following change to my code seems to have fixed this problem for me.

services.AddControllers().AddJsonOptions(options => options.JsonSerializerOptions.PropertyNamingPolicy = null);

Thanks so much for your help with this.

Kind regards,
Stuart


RS Renjith Singh Rajendran Syncfusion Team April 1, 2020 05:59 AM UTC

Hi Stuart, 

Thanks for your update. 

We are glad to hear, that you have achieved your requirement. 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



AS Alexandre Silva May 24, 2020 04:44 AM UTC

Hello, I'm having exactly the same problem, but I'm using Blazor WebAssembly, the official version that was released this week on MS Build. The interesting thing is that when I generate from the current page it works perfectly well, but when I have to generate from all the pages it is left with blank lines. I'm using WebApi as a data source and the URL call to bring all the data is working perfectly (following by the browser devtools).
In the WebAssembly version I was unable to add the suggested code, as .AddControllers () just doesn't exist.
Best regards,
Alexandre


RS Renjith Singh Rajendran Syncfusion Team May 25, 2020 11:45 AM UTC

Hi Alexandre, 

Greetings from Syncfusion support. 

We have prepared a WebAssembly hosted sample to bind WebApi service as data to Grid using WebApiAdaptor. We have added the below code in the Startup.cs of the Server project folder in the hosted application. We will be fetching the data from webapi service controller in the server project folder using WebApiAdaptor.  
 
We are attaching the sample for your reference, please download the sample from the link below,  

[Startup.cs] 
 
public void ConfigureServices(IServiceCollection services) 
{ 
    services.AddControllersWithViews(); 
    services.AddRazorPages(); 
    services.AddControllers().AddNewtonsoftJson(options => 
    { 
        options.SerializerSettings.ContractResolver = new DefaultContractResolver(); 
    }); 
} 


For this we need to install the below package in your application, 

<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0" />

If we have misunderstood your query, or if you still face difficulties in achieving your requirement, then kindly get back to us with the following details for better assistance. 
  1. Share the sample which you have tried from your side.
  2. Share the complete Grid code and web api controller codes.
  3. Share the screenshot/video demo showing the problem and exported file.

The provided information will help us analyze the problem, and provide you a solution as early as possible. 

Regards, 
Renjith Singh Rajendran 



AS Alexandre Silva May 25, 2020 09:10 PM UTC

Thanks for the answer, I downloaded the example and it worked fine, but the solution was applied on the server side which for me will be a problem, as I need to send the method names with the first lowercase letter, due to a legacy application that uses the API , so I couldn't be changing this information.
I attached your project again with a change in the Shared / Data / Orders.cs class to see if there is such a possibility of use, forcing the properties name in a json serialization / deserialization with the [JsonProperty ("nameProperty")] attribute or something like this, without the need to change the server side.
Best regards,
Alexandre

Attachment: SyncfusionBlazorApp1_newSample_f055a6b3.zip


RS Renjith Singh Rajendran Syncfusion Team May 26, 2020 08:48 AM UTC

Hi Alexandre, 

Thanks for your update. 

Based on your scenario, we suggest you to set the JsonProperty as like the below code to overcome the problem you are facing. Please use as like the code below, 

 
public class Orders 
{ 
    ... 
    [JsonProperty("OrderID")] 
    public long OrderID { getset; } 
    [JsonProperty("CustomerID")] 
    public string CustomerID { getset; } 
    ... 
} 


We have also modified the sample based on this scenario for your convenience. Please download the sample form the link below, 

Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran 



AS Alexandre Silva May 26, 2020 03:22 PM UTC

The problem in this scenario that you went through is that the server will generate JSON content with the characters starting in capital letters, because the class is shared, so it worked in this test. I'm going through the test again, this time, without the shared class, I'm creating a new model / orders class in the Wasm project and leaving the server in the standard form (with the first characters in lowercase), because as I informed you, I need to receive the data from this way (I have no way to change the data received. Sorry for the insistence.

Correct data received:



Incorrect data received:



If I create the class as in the image below (properties starting in lowercase) the excel export works normal, but it deviates from the C # standard for naming properties.



This other way, using JsonProperty doesn't really work, and it would be the expected way




Attachment: SyncfusionBlazorApp1_f0f576da.zip


RS Renjith Singh Rajendran Syncfusion Team May 29, 2020 06:21 AM UTC

Hi Alexandre, 

Greetings from Syncfusion support. 

Based on your requirement, we suggest you to dynamically change the column Field name value during Excel exporting by using the “Custom Column Exporting” feature of Grid. Now you can change the corresponding column’s field name dynamically and pass it as argument for Grid’s ExcelExport. We have modified the sample based on this suggestion. Please download the sample from the link below, 
 
Please refer the code below, 

 
SfGrid<OrdersGrid; 
public void ToolbarClick(Syncfusion.Blazor.Navigations.ClickEventArgs args) 
{ 
    if (args.Item.Id == "Grid_excelexport") 
    { 
 
        ExcelExportProperties ExportProperties = new ExcelExportProperties(); 
        ExportProperties.ExportType = ExportType.AllPages; 
 
        var columns = (List<GridColumn>)this.Grid.Columns;     //get the columns available in Grid 
        foreach (var col in columns) 
        { 
            var NewColName = col.Field.Substring(0, 1).ToLower() + col.Field.Substring(1);   //modify the field name value 
            col.Field = NewColName;                                                          //Assign modified field name as export grid's field name 
        } 
        ExportProperties.Columns = columns; 
        this.Grid.ExcelExport(ExportProperties); 
    } 
} 
 
 
Please get back to us if you need further assistance. 

Regards, 
Renjith Singh Rajendran. 



CR Chris Rowe May 30, 2024 04:03 PM UTC

We are running into this same issue even after applying all of the fixes listed here.

Exporting grids in WASM is resulting in Excel (.xlsx) and CSV files that appear blank/empty. The grid's DataSource is an in-memory collection and the grid itself is rendering in the UI will all of the data fine. Just getting empty files. Its worth noting, exporting from a grid with 3 records reuslts in a smaller csv file and exporting wfrom a grid showing a large number of records creates a bigger CSV file with more carriage returns and white space characters.

Examining the CSV in notepad, its just a bunch of single white space character separated by carriage returns
Image_6639_1717084969900
Image_1194_1717084942177



PS Prathap Senthil Syncfusion Team May 31, 2024 12:24 PM UTC

Hi Chris,

Based on the reported problem, we suspect that have used the template column, so we suggest including the template columns in the exported Excel file. To do this, set the IncludeTemplateColumn property of ExcelExportProperties to true. Here’s a code snippet that demonstrates how to achieve this. Please refer to the code snippet and documentation below for your reference.


  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.IncludeTemplateColumn = true;

          await this.DefaultGrid.ExcelExport(ExcelProperties);

      }

  }

 



UG: https://blazor.syncfusion.com/documentation/datagrid/template-excel-export#exporting-with-column-template

Regards,
Prathap Senthil



CR Chris Rowe May 31, 2024 02:10 PM UTC

This corrected my issue! Thank you!


I had seen the boolean flag in the documentation but misunderstood what it was going to do. I thought it was going to try to render my render fragment inside the Excel cells so I avoided it. I didn't realize it's essentially "export columns even if I defined a template for them"



PS Prathap Senthil Syncfusion Team June 4, 2024 03:01 AM UTC

Thanks for the update, we glad to hear that the provide solution resolved your issue.

Note: The IncludeTemplateColumn set to True determines whether columns using templates should be included in the export.


Loader.
Up arrow icon