@(Html.EJ().Grid<object>("FlatGrid") .Datasource((IEnumerable<object>)ViewBag.datasource) .AllowPaging() /*Paging Enabled*/ .PageSettings(eve=>eve.PageSize(3)) .EditSettings(edit => { edit.AllowAdding().AllowDeleting().AllowEditing(); }) .ToolbarSettings(toolbar => { toolbar.ShowToolbar().ToolbarItems(items => { items.AddTool(ToolBarItems.Add); items.AddTool(ToolBarItems.Edit); items.AddTool(ToolBarItems.Delete); items.AddTool(ToolBarItems.Update); items.AddTool(ToolBarItems.Cancel); }); }) .Columns(col => { .. col.Field("LocationType").HeaderText("LocationType").EditTemplate(a => { a.Create("create").Read("read").Write("write"); }).TextAlign(TextAlign.Right).Width(90).Add(); .. })) <script type="text/javascript"> function create() { return $("<input>"); } function write(args) { obj = $('#FlatGrid').ejGrid('instance'); var data = @(Html.Raw(Json.Encode(ViewData["EmployeeID"]))); args.element.ejDropDownList({ width: "100%", dataSource: data}); } function read(args) { return args.ejDropDownList("getSelectedValue"); } </script> GridController.cs public ActionResult GridFeatures() { ViewData["EmployeeID"] = EmployeeID; return View(); } public List<object> EmployeeID { get { var EmployeeID = new List<object>(); Type enumType = typeof(LocationType); // I will get all values and iterate through them var enumValues = enumType.GetEnumValues(); foreach (LocationType value in enumValues) { MemberInfo memberInfo = enumType.GetMember(value.ToString()).First(); var descriptionAttribute = memberInfo.GetCustomAttribute<DescriptionAttribute>(); LocationType eval2 = value; int value1 = (int) eval2; EmployeeID.Add(new { value = value, text = descriptionAttribute.Description }); } return EmployeeID; } } 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; } [DisplayName("Location Type")] public LocationType? LocationType { get; set; } } public enum LocationType { [Description("Description 1")] EST = 1, [Description("Description 2")] INTNS = 2, [Description("Description 3")] INTS = 3 } } } |
Hi, I implement this solution and works perfect. Currently I am trying to do 2 things: