Dynamic Grid column editor template is sending null data

2 posts, 0 answers
  1. Alex
    Alex avatar
    75 posts
    Member since:
    May 2015

    Posted 19 Dec 2017 Link to this post

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

     

     

  2. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    2466 posts

    Posted 21 Dec 2017 Link to this post

    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.
Back to Top