This is a migrated thread and some comments may be shown as answers.

Enum value not rendered in grid

2 Answers 787 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel Blendea
Top achievements
Rank 1
Daniel Blendea asked on 19 Aug 2019, 02:08 PM

Hi,

I'm trying to use the Grid inTelerik UI for ASP.NET Core with a remote datasource:

@(Html.Kendo().Grid<DashboardEntry>()
.Name("dashboardGrid")
.Columns(columns =>
{

columns.Bound(p => p.Id).Width(50);
  columns.Bound(p => p.State).Width(100); --> Enum property

})
.AutoBind(false)
.DataSource(dataSource =>
dataSource
.Ajax()
.ServerOperation(true)
.Batch(true)
.PageSize(20)
.Model(model => model.Id(p => p.Id))
.Read(read =>
read.Url("http://localhost:5000/dashboard/entries")
.Type(HttpVerbs.Get))
.Events(events => events.Error("error_handler"))
)
)

The json from server looks like this:

{

Data:[

{0: {Id: 22041, State: "Draft" },

{0: {Id: 22042, State: "Complete" }

],

Total: 2

}

Practically, the enum is actually a string, thanks to a StateConverter : JsonConverter.

But nothing is rendered/displayed in the State column.

How can I make it work?

Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Tsvetomir
Telerik team
answered on 22 Aug 2019, 12:47 PM
Hi Daniel,

The Enum is a key-value pair. And the grid is able to consume enumerations out-of-the-box. I am attaching a sample project to this response with a grid. One of its fields is bound to an Enum and it is shown automatically.

public enum AlertActive
{
    All = 0,
    Inactive = 1,
    Active = 2
}

Give it a try and let me know in case the issue is still present.


Best regards,
Tsvetomir
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Daniel Blendea
Top achievements
Rank 1
answered on 22 Aug 2019, 02:25 PM

Ok, thank you.

The enum is bound and displayed correctly.

My datasource is a REST service, and I was processing the enums so they are also displayed nicely in the existing UI.

But with Telerik that processing is no longer necessary.

Tags
Grid
Asked by
Daniel Blendea
Top achievements
Rank 1
Answers by
Tsvetomir
Telerik team
Daniel Blendea
Top achievements
Rank 1
Share this question
or