Display Enum string value in grid

Hello,

I want to display a string value from an enum in a grid, as a text, but I didn't find a solution .. Below you can find the enum and the grid (see the highlighted row). When my page is loaded, the value for r.RezolutieAsteptare is 1, how can i show the display name instead of the int?

The enum:

    public enum RezolutieAsteptare
    {
        [Display(Name = "CRM")] Crm = 1,
        [Display(Name = "NU DOREȘTE")] NuDoreste = 2,
        [Display(Name = "DATE ERONATE")] DateEronate = 3
    }

The grid:

    <div class="container-fluid">
        @(Html.EJ().Grid<Recomandare>("RecomandariInLucruGrid")
                      .Datasource(Model)
                      .AllowSorting()
                      .AllowFiltering()
                      .AllowPaging()
                      .PageSettings(p => p.PageSize(25))
                      .AllowResizeToFit()
                      .IsResponsive()
                      .Columns(col =>
                      {
                          col.Field(r => r.ResourceId).HeaderText("ResourceId").IsPrimaryKey(true).Visible(false).Add();
                          col.Field(r => r.ResourceId).HeaderText("FormInstanceId").IsPrimaryKey(true).Visible(false).Add();
                          col.Field(r => r.Client).HeaderText("Client").Priority(1).Add();
                          col.Field(r => r.Id).HeaderText("Id").Priority(2).Add();
                          col.Field(r => r.Data).Format("{0:dd.MM.yyyy}").HeaderText("Data").Priority(3).Add();
                          col.Field(r => r.DataInLucru).Format("{0:dd.MM.yyyy}").HeaderText("In lucru").Priority(4).Add();
                          col.Field(r => r.DataParcat).Format("{0:dd.MM.yyyy}").HeaderText("Parcat").Priority(75).Add();
                          col.Field(r => r.RezolutieAsteptare).HeaderText("Rez. astept.").Priority(6).Add();
                          col.Field(r => r.DataFinalizat).Format("{0:dd.MM.yyyy}").HeaderText("Finalizare").Priority(7).Add();
                          col.Field(r => r.RezolutieFinalizare).HeaderText("Rezolutie").Priority(8).Add();
                      })
                      .ClientSideEvents(eve => eve.QueryCellInfo("querycellinfo")))
    </div>

Thanks,
Cristina

5 Replies

KM Kuralarasan Muthusamy Syncfusion Team July 20, 2018 12:45 PM UTC

Hi Cristina, 

Thanks for contacting Syncfusion support. 

We have analyzed your query and we found that you want to display the Enum name instead of Enum value in Grid. But before validate your requirement,  we need your Essential studio version to provide the solution for this. So please share your Essential studio version for further assistance. 

Regards, 
Kuralarasan M. 



CP Cristina Pelivan July 23, 2018 06:06 AM UTC

Hello,
I am using Syncfusion.AspNet.Mvc5, version 16.1.0.37


Thank you,
Cristina.


KM Kuralarasan Muthusamy Syncfusion Team July 24, 2018 01:00 PM UTC

Hi Cristina, 

We suggest you to add EnumMember attribute with the display attribute of enum values to achieve your requirement. We have displayed this EnumMember value in Grid column instead of enum value. By default, the JavaScriptSerializer is used to serialize the DataSource in Grid. It serializes the enum to numeric values and not their string representation. So, If you want to serialize the enum as its name instead of numeric value, we suggest you to use the custom serializer in DataManager. Please refer the following code snippet: 
 
Client Side: 
 
@using F138823.Controllers 
@using Syncfusion.JavaScript.Shared.Serializer 
@{ 
    DataManagerConverter.Serializer = new DMSerial(); 
} 
@(Html.EJ().Grid<object>("FlatGrid") 
         
             ...... 
 
) 
 
Controller Side: 
 
   namespace F138823.Controllers 
{ 
    public class DMSerial : IDataSourceSerializer 
    { 
        public string Serialize(object obj) 
        { 
            return Serialize(obj, null); 
        } 
        public string Serialize(object obj, object settings = null) 
        { 
            var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj); 
            return str; 
        } 
    } 
    public class GridController : Controller 
    { 
 
        public class Details 
        { 
            public int OrderID { get; set; } 
            public DateTime OrderDate { get; set; } 
            public string FirstName { get; set; } 
            public string LastName { get; set; } 
            public string Title { get; set; } 
            [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 
            public UnitOfMeasure Unit { get; set; } 
        } 
        public enum UnitOfMeasure 
        { 
            [EnumMember(Value = "Number"), Display(Name = "Number")] 
            Nr = 0, 
            [EnumMember(Value = "Kilogram"), Display(Name = "Kilogram")] 
            Kg = 1, 
            [EnumMember(Value = "Gram"), Display(Name = "Gram")] 
            g = 2, 
            [EnumMember(Value = "Liter"), Display(Name = "Liter")] 
            l = 3              
        } 
    } 
} 
 
In this code we have added the EnumMember attribute with the display attribute and we have used the Newtonsoft.Json to serialize the enum values are converted into string by using the Newtonsoft StringEnumConverter. We have prepared the sample with your requirement and that sample can be downloadable from the below link, 
 
 
Please refer this sample for your clarification. 
 
Regards, 
Kuralarasan M. 



CP Cristina Pelivan July 25, 2018 08:12 AM UTC

Thank you,

This solved my issue.


KM Kuralarasan Muthusamy Syncfusion Team July 26, 2018 12:26 PM UTC

Hi Cristina, 
 
Thanks for the update, We are happy to hear that your requirement has been achieved.

 
Regards, 
Kuralarasan M. 


Loader.
Up arrow icon