Inline editing mode and dynamic object

6 posts, 0 answers
  1. siham
    siham avatar
    1 posts
    Member since:
    Jan 2014

    Posted 16 Jan 2014 Link to this post

    Hi,

    I've created a grid with a dynamic object and I'd like to use the GridEditMode.InLine to update and add data. The popUp mode is working but with the InCell and
    the inline I'm getting the following error:

    Templates can be used only with field access, property access, single-dimension array index, or single-parameter custom indexer expressions.

    Am I missing something?

    I tried to use a custom template but I am still getting the same error.
    @(Html.Kendo().Grid<dynamic>()
        .Name("Grid")
        .DataSource(dataSource => dataSource
            .Ajax()
            .ServerOperation(true)
            .Model(cfg =>
             {
               cfg.Id("SsdID");
            foreach (var property in Model.PropertyDescriptors)
                {
                    cfg.Field(property.Name, property.DataType);
                 }
             })
            .Read(cfg => cfg.Type(HttpVerbs.Post)
            .Action("ReadDataForDefinition", "ManualDataEntry",
                    new { id = Model.LDefinitionId }))
            .Update(u => u.Type(HttpVerbs.Post).Action("UpdateDataForDefinition", "ManualDataEntry",
                    new { id = Model.LDefinitionId }))
            .Create(u => u.Type(HttpVerbs.Post).Action("Create", "ManualDataEntry",
                    new { id = Model.LDefinitionId }))
             )
          .Resizable(resizing => resizing.Columns(true))
          Columns(columns =>
          {
            foreach (var property in Model.PropertyDescriptors.Where(desc => desc.DisplayOrder.HasValue))
             {
                 var binding = columns.Bound(property.DataType, property.Name);
              if (property.DataType == typeof(DateTime) || property.DataType == typeof(DateTime?))
               binding.Format("{0:d}");
               binding.Column.Title = property.Label;
              }
          columns.Command(command =>
            {
                command.Edit();
                command.Destroy();
            });
         })
      .ToolBar(toolbar => { toolbar.Create(); })
      .Pageable(paging =>
       {
            paging.ButtonCount(10);
            paging.PreviousNext(true);
            paging.PageSizes(true);
        })
      .Editable(edit => edit.Mode(GridEditMode.InLine))
      .Sortable()
      .Scrollable()
      .Filterable()
    )
    Thanks!
  2. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 17 Jan 2014 Link to this post

    Hi Siham,

    Basically the error is thrown as internally the Grid builds the default editor templates by calling the "EditorForModel" which doesn't support dynamic type. In order to support different edit modes you should create custom editor template for the model. For more information about setting custom editor templates you can check the following help topic:

    Regards,
    Vladimir Iliev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. Louis
    Louis  avatar
    14 posts
    Member since:
    Mar 2011

    Posted 03 Apr 2014 in reply to Vladimir Iliev Link to this post

    I am trying to do something similar, so when I looked into creating the new Editor Templates, it appears you have to set the UIHint attribute on the model. If the model is not created at design time, which is what siham appears to be doing in his example, how to do you tie an Editor Template to a dynamic property?
  5. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 07 Apr 2014 Link to this post

    Hi Louis,

    You can specify the editor template using the "TemplateName" method:

    .Editable(e => e.Mode(GridEditMode.PopUp).TemplateName("customTemplate"))

    Regards,
    Vladimir Iliev
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  6. gregtayl
    gregtayl avatar
    8 posts
    Member since:
    Jan 2012

    Posted 13 Sep in reply to Vladimir Iliev Link to this post

    I realize this is an old post, however the 'Model' that gets provided to editor template is null so you end up losing context as to which property you are editing.

    MyEditor.cshtml

    @model decimal
    @{
       // Model == null, so the following line returns an empty string for propertName
       var propertyName = ModelMetadata.FromLambdaExpression(o => o, Html.ViewData).PropertyName;
    }
    <input data-role="numerictextbox" data-bind="value:@propertyName"/>

    @(Html.Kendo().Grid(new dynamic[] {})
            .Editable(c => c.Mode(GridEditMode.InCell))
            .Columns(columns =>
            {
                ...
                columns.Bound(typeof(decimal), "UnitPrice").EditorTemplateName("MyEditor");
            }))

  7. Vladimir Iliev
    Admin
    Vladimir Iliev avatar
    2172 posts

    Posted 14 Sep Link to this post

    Hi Greg,

    This behavior is expected as the editor template is executed only once on the server side with empty instance of the Grid model type. Later on the client side the currently edited model is bound to the template HTML output using MVVM.

    Regards,
    Vladimir Iliev
    Telerik by Progress
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET MVC is VS 2017 Ready