The model defined below on kendo ui datasource strips off the time portion of the StartDate and EndDate when deserialized on client. I tried setting the model type to "datetime" but that didn't seem to work. If i remove the model then the time portion is not lost but i have to do ISO date parsing manuallly. What am i doing wrong?
More info:
I'm using web api controller that returns dates in ISO 8601 format.
More info:
I'm using web api controller that returns dates in ISO 8601 format.
schema: {
errors:
function
(response) {
return
response.errors;
},
model: {
id:
"ItemID"
,
fields: {
"Subject"
: { type:
"string"
},
"StartDate"
: { type:
"date"
},
"EndDate"
: { type:
"date"
}
}
}
},
5 Answers, 1 is accepted
0
Hi Brian,
Your code looks OK, there is no "datetime" field - the correct type is "date" and it holds information about both date and time portions.
The build-in DataSource parser uses kendo.parseDate to parse the incoming formatted string as JavaScript date. I tested both if kendo.parseDate parses date in ISO 8601 format and if the same works as expected in the DataSource and received a positive result.
Could you please check my test page and let me know what I am missing?
Regards,
Alexander Valchev
the Telerik team
Your code looks OK, there is no "datetime" field - the correct type is "date" and it holds information about both date and time portions.
The build-in DataSource parser uses kendo.parseDate to parse the incoming formatted string as JavaScript date. I tested both if kendo.parseDate parses date in ISO 8601 format and if the same works as expected in the DataSource and received a positive result.
kendo.parseDate(
"2010-03-07T12:44:07Z"
);
//returns Sun Mar 07 2010 14:44:07 GMT+0200 (FLE Standard Time)
Could you please check my test page and let me know what I am missing?
Regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Ray
Top achievements
Rank 1
answered on 05 Oct 2012, 01:53 AM
Hi Alexander
I have same problem like Brian.
I use your test page and figure out what's different.
this is my test page http://jsfiddle.net/ray521/nbjr9/24/
I added foo 4 and bar's datetime is 2012-09-26T11:56:38.807
I have same problem like Brian.
I use your test page and figure out what's different.
this is my test page http://jsfiddle.net/ray521/nbjr9/24/
I added foo 4 and bar's datetime is 2012-09-26T11:56:38.807
0
Brian
Top achievements
Rank 1
answered on 06 Oct 2012, 04:01 PM
Hi Ray,
I found that you have to include timezone in your json date serialization. In mvc4 project i had to add the following to my WebApiConfig under the App_Start folder:
Note, you can also use DateTimeZoneHandling.Utc if you store dates in UTC in your db. Hope that helps.
I found that you have to include timezone in your json date serialization. In mvc4 project i had to add the following to my WebApiConfig under the App_Start folder:
config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Local;
Note, you can also use DateTimeZoneHandling.Utc if you store dates in UTC in your db. Hope that helps.
0
Sypher
Top achievements
Rank 1
answered on 09 Oct 2012, 03:11 PM
Brian,
Thanks! That worked for me as well. My times were being dropped until I added those config settings. My only changes were to use UTC and place the code in the Application_Start of my Global.asax file (since I'm using Web API in ASP.NET WebForms):
Bryan
Thanks! That worked for me as well. My times were being dropped until I added those config settings. My only changes were to use UTC and place the code in the Application_Start of my Global.asax file (since I'm using Web API in ASP.NET WebForms):
HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
config.Formatters.JsonFormatter.SerializerSettings.DateTimeZoneHandling = Newtonsoft.Json.DateTimeZoneHandling.Utc;
Bryan
0
Ray
Top achievements
Rank 1
answered on 11 Oct 2012, 01:04 AM
Thanks Brian.
It's work !
It's work !