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

Grid editing values with a dropdown selection

0 Answers 151 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Levi
Top achievements
Rank 1
Levi asked on 13 Nov 2012, 03:50 PM
I just got started with Kendo UI - thinking about switching from Telerik MVC controls. Right off the bat, editing in grids seems like a nightmare. Hopefully someone can help me out here.

Lets say I have a simplified domain model of:
public class User
{
   public Guid UserId { get; set; }
   public string Name { get; set; }
   public Guid TimeZoneId { get; set; }
}
And then I try to make a view model that has to serve as both an EditModel and ViewModel (because of a Kendo limitation? see further below)
public class UserViewModel
{
   public Guid UserId { get; set; }
   public string Name { get; set; }
   public Guid TimeZoneId { get; set; }
   public string TimeZoneName { get; set; }
}
Okay, so lets say I pass a list of UserViewModels to the view and sneak in a list of TimeZoneModels to the ViewBag.

I then add this to my view:
    <%: Html.Kendo().Grid(Model.Users)
    .Name("Grid")
    .Columns(columns =>
    {
        columns.Bound(p => p.UserId);
        columns.Bound(p => p.Name);
        columns.Bound(p => p.TimeZoneName);
        columns.Bound(p => p.TimeZoneId).EditorTemplateName("TimeZoneId");
        columns.Command(command => { command.Edit(); command.Destroy(); });
    })
    .Editable(editable => editable.Mode(GridEditMode.InLine))
    .DataSource(dataSource => dataSource
        .Ajax()
           .Model(model =>
           {
               model.Id(p => p.UserId);
           })
        .Read(read => read.Action("EditingInline_Read", "Grid"))
        .Update(update => update.Action("EditingInline_Update", "Grid"))
        .Destroy(update => update.Action("EditingInline_Destroy", "Grid")))
%>
With an edit template named TimeZoneId.ascx
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
<% Html.Kendo().DropDownList()
    .Name("TimeZoneId")
    .DataValueField("TimeZoneId")
    .DataTextField("Name")
    .BindTo(ViewBag.TimeZones).Render();
%>
Okay, here's where it gets fuzzy.

1. First off, when clicking edit for this, It edits inline great. When switching to Popup however, the editor template is not used. What gives?
2. Secondly, how do you manage this properly? I needed a TimeZoneName to show the name in the grid, but in order to preserve a timeZoneId when creating or editing a user, I need to have a TimeZoneId field on the model as well. So, how do you show just the TimeZoneName when displaying while hiding the TimeZoneId. Then hiding the TimeZoneName when editing and showing the TimeZoneId with a dropdown. It doesn't appear this is thought through very well here. How is everyone else handling this?

-Levi

No answers yet. Maybe you can help?

Tags
Grid
Asked by
Levi
Top achievements
Rank 1
Share this question
or