Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display enum description or name in a grid row?

I am using the Kendo grid in my ASP.Net MVC application. If I have the following grid definition,

@(Html.Kendo().Grid(Model) //Bind the grid to ViewBag.Products
  .Name("grid")
  .Columns(columns =>
  {
      columns.Bound(p => p.FullName);
      columns.Bound(p => p.MyEnum)
  })
  .Groupable()
  .Pageable()
  .Sortable()
  .Scrollable(scr => scr.Height(600))
  .Filterable()
  )

where one of the column is an Enum. My enum definition is:

public enum MyEnum
{
    [Display(AutoGenerateField = false, Name = "My enum 1", Description = "My Enum 1")]
    EnumOne,
    [Display(Name = "My Enum 2")]
    EnumTwo
}

How do I make it display "My Enum 1" or "My Enum 2" for each row?

Thanks in advance!

like image 593
wm_ Avatar asked Oct 26 '13 16:10

wm_


1 Answers

I recently ran into this problem and solved it by using

var someArrayOfValueAndText = new[] {new  {
    Id = 0, Description = "Foo"
}, new  {
    Id = 1, Description = "Bar"
}
.Columns(c.ForeignKey(m=> m.MyEnum, someArrayOfValueAndText, "Id","Description"))

instead of the .Bound method

like image 107
Driven-it Avatar answered Oct 01 '22 14:10

Driven-it