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

Inline editing mode and dynamic object

7 Answers 681 Views
Grid
This is a migrated thread and some comments may be shown as answers.
siham
Top achievements
Rank 1
siham asked on 16 Jan 2014, 08:57 AM
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!

7 Answers, 1 is accepted

Sort by
0
Vladimir Iliev
Telerik team
answered on 17 Jan 2014, 01:07 PM
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!
0
Louis
Top achievements
Rank 1
answered on 03 Apr 2014, 06:27 PM
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?
0
Vladimir Iliev
Telerik team
answered on 07 Apr 2014, 08:02 AM
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.

 
0
gregtayl
Top achievements
Rank 1
answered on 13 Sep 2016, 07:05 PM

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");
        }))

0
Vladimir Iliev
Telerik team
answered on 14 Sep 2016, 07:17 AM
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
0
Christian
Top achievements
Rank 1
Iron
answered on 02 Jul 2019, 01:19 PM
Why do I get the same error when only adding a delete button?
Can I avoid calling the editor template, since I don't need it in this case.
....Columns(columns =>
{
    foreach (var prop in properties)
    {
        columns.Bound(prop.Name);
    }
    columns.Command(command => command.Destroy());
})....

0
Tsvetomir
Telerik team
answered on 04 Jul 2019, 08:49 AM
Hi Christian,

Generally, adding a simple Delete button in the command column of the grid should not be affecting the overall behavior at all. I have tested out a similar case and it appears that the error is not encountered. It is mandatory for the Destroy functionality to have set the data source as follows:

.DataSource(d=>d.Server()
    .Model(m=>m.Id(id=>id.ProductID))
    .Destroy("Action", "Controller")
    .Update("Action", "Controller"))

And the columns declaration is set as follows:

.Columns(columns => {
    foreach(var item in properties)
    {
        columns.Bound(item);
    }
    columns.Command(cmd => cmd.Destroy());
})

I suspect that the issue might stem from something else. Is it possible for you to isolate the faulty behavior in a sample project and send it back to me? This way I would have the opportunity to investigate the case and get back to you with accurate suggestions.

Looking forward to your reply.


Kind 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.
Tags
Grid
Asked by
siham
Top achievements
Rank 1
Answers by
Vladimir Iliev
Telerik team
Louis
Top achievements
Rank 1
gregtayl
Top achievements
Rank 1
Christian
Top achievements
Rank 1
Iron
Tsvetomir
Telerik team
Share this question
or