daniel damianov
daniel damianov

Reputation: 49

Kendo UI DateTime

I use Kendo UI for the first time and had a little problem. When I made a class with DateTime property and implement it in Kendo Grid, the field for DateTime always shows this "The field DateOfLastCheck must be a date.".I tried all, changed order, put an attribute, but always the same. This is my Kendo code:

@(Html.Kendo().Grid<Models.OvergasClient>()
      .Name("grid")

      .Columns(columns =>
      {
          columns.Bound(c => c.Name).Width(200);
          columns.Bound(c => c.Address).Width(200);
          columns.Bound(c => c.AddressNumber).Width(200);
          columns.Bound(c => c.Floor).Width(200);
          columns.Bound(c => c.Appartment).Width(200);
          columns.Bound(c => c.RegNumber).Width(200);
          columns.Bound(c => c.Telephone).Width(200);
          columns.Bound(c => c.isChecked).Width(200);
          columns.Bound(c => c.DateOfLastCheck).Format("{0:yyyy/mm/dd}").Width(200);
          columns.Bound(c => c.EquipmentNumber).Width(200);
          columns.Bound(c => c.Type).Width(200);
          columns.Bound(c => c.Note).Width(200);
          columns.Bound(c => c.Status).Width(200);
          columns.Bound(c => c.Inspector).Width(200);
          columns.Bound(c => c.Editor).Width(200);
          columns.Command(command => { command.Edit().UpdateText("Запази").CancelText("Откажи").Text("Редактирай"); command.Destroy().Text("Изтрий"); }).Width(180);
      })
      .ToolBar(toolbar => {
          toolbar.Create().Text("Създай");

      })

      .ColumnMenu()
      .HtmlAttributes(new { style = "height:450px;" })
      .Editable(editable => editable.Mode(GridEditMode.PopUp))
      .Pageable(p => p.Refresh(true).PageSizes(true).ButtonCount(5))

      .Selectable(selectable =>
      {
          selectable.Mode(GridSelectionMode.Single);
          selectable.Type(GridSelectionType.Row);
      })

      .Sortable(sortable =>
      {
          sortable.SortMode(GridSortMode.SingleColumn);

      })
      .Filterable()
      .Scrollable()
      .Groupable(m=>m.Messages(c=>c.Empty("Постави името на колоната тук, за да сортираш по тази колона")))
      .Events(events => {
          events.Cancel("onCancel");
          events.Change("onChange");
          events.ColumnHide("onColumnHide");
          events.Edit("onEdit");
          events.SaveChanges("onSaveChanges");
          events.Save("onSave");
          events.Remove("onRemove");

          events.DetailExpand("onDetailExpand");
          events.DataBinding("onDataBinding");
          events.DataBound("onDataBound");
          events.ColumnShow("onColumnShow");
      })
      .DataSource(dataSource => dataSource
          .Ajax()
          .Model(model =>
          {
              model.Id(m => m.Id);
              model.Field(m => m.DateOfLastCheck).Editable(true);

          })
          .Read(read => read.Action("OvergasClients_Read", "OGTechnika"))
          .Create(create => create.Action("OvergasClients_Create", "OGTechnika"))
          .Update(update => update.Action("OvergasClients_Update", "OGTechnika"))
          .Destroy(destroy => destroy.Action("OvergasClients_Destroy", "OGTechnika"))
      )
)

Upvotes: 2

Views: 360

Answers (3)

fdsafdsafdsafdsafs
fdsafdsafdsafdsafs

Reputation: 169

For this you will want to set up a ViewModel, and set all date fields to a System.DateTime. Then bind the fields of the grid to use that ViewModel. I struggled with that for about an hour. The format is incorrect, but that will not prevent the data from displaying. I just tested that on one of my old Grid Project.

Upvotes: 0

Jaya
Jaya

Reputation: 3911

Based on docs here here http://docs.telerik.com/kendo-ui/framework/globalization/dateformatting mm denotes minutes and not month. Also is your DateOfLastCheck attribute nullable ? You may want to check that too.

Upvotes: 0

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241525

Your code:

columns.Bound(c => c.DateOfLastCheck).Format("{0:yyyy/mm/dd}").Width(200);

Note that mm is for minutes. You probably want MM for months here.

My guess is that you have something like 2016/59/29, because of this, which is clearly not a valid date.

Upvotes: 1

Related Questions