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

Dynamic Grid column editor template is sending null data

1 Answer 228 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 19 Dec 2017, 09:30 PM

We are using a Grid with a dynamic type. This has been working for us until we ran into the problem of a column editor template receiving null data. The editor template accepts non-nullable TimeSpans but when the grid initializes it is trying to send this editor template a null TimeSpan object. When I change the grid to one of the classes it should be getting such as DownTimeViewModel this error doesn't happen.

 

"Message: The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.TimeSpan'."

 

@(Html.Kendo().Grid<dynamic>()
      .Name("SomeName")
      .Columns(columns =>
      {
          foreach (Field field in cols)
          {
 
              if (string.IsNullOrWhiteSpace(field.EditorTemplateName))
              {
                  throw new NotImplementedException("EditorTemplate is not set and it needs to be");
              }
 
              columns.Bound(field.Member)
                  .Title(field.Title)
                  .Visible(field.Visible)
                  .Hidden(field.Hidden)
                  .Filterable(field.Filterable)
                  .IncludeInMenu(field.IncludeInMenu)
                  .Encoded(field.Encoded)
                  .Format(field.Format)
                  .Width(field.Width)
                  .Sortable(field.Sortable)
                  .ClientTemplate(field.ClientTemplate)
                  .EditorTemplateName(field.EditorTemplateName)
                  .HeaderHtmlAttributes(field.HeaderHtmlAttributes)
                  .EditorViewData(Util.CreateNewObject(field.AdditionalViewData));
 
          }
      })
      .Scrollable()
      .ToolBar(toolbar =>
      {
          toolbar.Create();
          toolbar.Custom().Text("Delete").Action("Grid_Delete", "Downtime", new { WONumber = Model.WONumber });
          //toolbar.Save();
      })
      .Editable(editable => editable.Mode(GridEditMode.InCell))
      .Sortable()
      .DataSource(dataSource => dataSource
        .Ajax()
        .Batch(true)
        .PageSize(5)
        .Model(model =>
        {
            foreach (Field field in cols)
            {
                model.Id(field.Member);
            }
 
            foreach (Field field in cols)
            {
                model.Field(field.Member, field.MemberType).DefaultValue(field.DefaultValue).Editable(field.Editable);
            }
        }
          )
          .Read(read => read.Action("Grid_Read", "Downtime", new { id = Model.WONumber.ToString() }))
          .Create(create => create.Action("Grid_Create", "Downtime"))
          .Update(update => update.Action("Grid_Update", "Downtime"))
          .Destroy(destroy => destroy.Action("Grid_Delete", "Downtime"))
      ))

 

 

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 21 Dec 2017, 09:26 AM
Hello Alex,

Could you please share the Editor template that you are using for the TimeSpan field and if possible, share the "cols" collection that you are using (or at least one that replicates the issue). Thus we will be able to create a runnable example on our end with the same Grid configuration and suggest a solution for the problem.

Looking forward to your reply.

Regards,
Konstantin Dikov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Grid
Asked by
Alex
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or