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

kendo Model not parsing Dates

1 Answer 66 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Roland
Top achievements
Rank 1
Roland asked on 30 Mar 2017, 11:35 AM

I've defined Models for all my data entities especially to assign date data types. When I use them inside a DataSource everything works fine. However if I try the model as stand-alone to create a model from JSON parsed data, the dates are not parsed.

Am I doing this wrong?

Here's a dojo:

http://dojo.telerik.com/olOce/2

Code:

var MyModel = kendo.data.Model.define({
      id: "id", // the identifier of the model
      fields: {
        myDate: { type: "date" }
      }
    });
        
    var inst = new MyModel({
    id: 10,
      myDate: "2017-03-30T00:45:11.804"
    });
    // should be "Date"
    alert(typeof inst.myDate);

1 Answer, 1 is accepted

Sort by
0
Veselin Tsvetanov
Telerik team
answered on 03 Apr 2017, 08:32 AM
Hello Roland,

In order to retrieve correctly the type of a Date object, you will need to assign to your model field a Date and not a string:
var inst = new MyModel({
  id: 10,
  myDate: new Date('2017-03-30T00:45:11.804')
});

Here you will find a modified version of the sample sent.

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