Export Enum String Descriptions

Hi, 

My grid displays the string descriptions of my enums but when exporting it exports them in raw form. How can I export them as string descriptions?

The Grid:

Screenshot 2024-11-16 181321.png

The Exported file:

Image_5784_1731773908253


1 Reply

PS Prathap Senthil Syncfusion Team November 20, 2024 04:45 AM UTC

Hi À la mode Clothing Outlet,


Greetings from Syncfusion,

Based on your requirement, we suggest using the ExcelQueryCellInfo event to export the Display name in the following way. Kindly refer to the code snippet and sample below for your reference.

  public void ExcelQueryCellInfoHandler(Syncfusion.Blazor.Grids.ExcelQueryCellInfoEventArgs<OrderData> args)

  {

      if(args.Column.Field == "Type")

      {

          var fileTypeString = args.Cell.Value.ToString();

 

        

          var fileType = (FileType)Enum.Parse(typeof(FileType), fileTypeString);

 

 

          var displayName = fileType.GetType()?.GetField(fileType.ToString())?.GetCustomAttribute<DisplayAttribute>()?.Name ?? fileType.ToString();

 

   

 

          args.Cell.Value = displayName;

      }

  }


Reference:
Events in Blazor DataGrid Component | Syncfusion

Sample:
https://blazorplayground.syncfusion.com/embed/VNBJsMMYqndaXvbj?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

Regards,
Prathap Senthil


Loader.
Up arrow icon