We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Show enum string values in grid with remote datasource

Thread ID:

Created:

Updated:

Platform:

Replies:

142951 Feb 26,2019 07:22 PM UTC Feb 28,2019 06:34 AM UTC ASP.NET MVC - EJ 2 3
loading
Tags: Grid
Tomislav Tustonic
Asked On February 26, 2019 07:22 PM UTC

Hello

Is it possible to show enum string names instead of int values for a grid with remote data source?
I have tried this:
https://www.syncfusion.com/forums/138484/enum-names-instead-of-int-values-in-asp-net-core-web-app-with-razor-pages
but it doesn't seem to work when I use DataManager with UrlAdaptor as a grid datasource.

Thanks, Tom

Madhu Sudhanan P [Syncfusion]
Replied On February 27, 2019 09:44 AM UTC

Hi Tomislav, 

Greeting from Syncfusion. 

We have validated the your query and checked with our end. By default, while creating MVC application(.Net core application uses Newtonsoft by default) it uses javascriptserializer so that it return enum values(int) instead of names. So we suggest you to use the below way to achieve your requirement. 

In the below sample, we have serialize Json object using Newtonsoft serializer instead of Javascript serializer. Please refer the below code example and sample for more information. 

   public ActionResult UrlDatasource(Data dm) 
        { 
            var order = OrdersDetails.GetAllRecords(); 
            var Data = order.ToList(); 
            int count = order.Count(); 
            // we have serialize the json object using newtonsoft 
            var SerializeData = Newtonsoft.Json.JsonConvert.SerializeObject(Data); 
            return dm.requiresCounts ? Json(new { result = SerializeData.Skip(dm.skip).Take(dm.take), count = count }): Json(SerializeData); 
        } 
    } 
    public class OrdersDetails 
    { 
        public OrdersDetails() 
        { 
 
        } 
        public OrdersDetails(int OrderID, string CustomerId, int EmployeeId, double Freight, bool Verified, DateTime OrderDate, string ShipCity, string ShipName, string ShipCountry, DateTime ShippedDate, string ShipAddress, state State) 
        { 
            . . . . . 
            this.ShipAddress = ShipAddress; 
            this.State = State; 
        } 
 
        public int? OrderID { get; set; } 
        public string CustomerID { get; set; } 
        . . . . .  
        [Newtonsoft.Json.JsonConverter(typeof(Newtonsoft.Json.Converters.StringEnumConverter))] 
        public state State { get; } 
    } 
    public enum state 
    { 
        [Display(Name = "Activated")] 
        Activated = 1, 
        [Display(Name = "Unactivated")] 
        Unactivated, 
} 



Regards, 
Madhu Sudhanan P 


Tomislav Tustonic
Replied On February 27, 2019 04:03 PM UTC

Hello

Thanks for the reply. This works fine to display enum strings, however, now the filter (FilterType.CheckBox) doesn't work.
I have created a workaround, by fixing Where values in DataManagerRequest before applying to DbContext, but it would be nice to have it fixed in queryable operation.

Tom

Madhu Sudhanan P [Syncfusion]
Replied On February 28, 2019 06:34 AM UTC

Hi Tomislav, 
  
Thanks for the suggestion. The string to Enum re-conversion should be handled at the server side before applying data operation. 
  
Regards, 
Madhu 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon