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

JSON date handling changed in latest release?

5 Answers 466 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Dr.YSG
Top achievements
Rank 2
Dr.YSG asked on 23 Apr 2012, 08:11 PM
In version v2011.3.1413, I had dates in a JSON data structure (returned by a WCF data service) of the form:

        "date":"1910-12-09T08:32:26",

I display the datasource a grid, and it sorted things properly (I am not sure if was just relying on string alphabetic sort or was really understanding the date format.

I specified, in the datasource schmea the following: (whhere I have two date fieds (date: and egplDate:)

model:{
    fields:{
        idx:{ type:"string" },
        classification:{ type:"string" },
        creator:{ type:"string" },
        date:{ type:"string" },
        elevation:{ type:"number" },
        datum:{ type:"string" },
        size:{ type:"number" },
        type:{ type:"string" },
        description:{ type:"string" },
        dirLocation:{ type:"string" },
        distributor:{ type:"string" },
        egplDate:{ type:"date" },
        handling:{ type:"string" },
        product:{ type:"string" },
        uniqID:{ type:"string" }
    }

In the Grid I do dipslay as follows:

columns:[
    {
        field:"creator",
        width:220
    },
    {
        field:"date",
        width:170
    }, (// etc.)

As I said this worked fine.

But I am now using the latest version of UI complete: v2012.1.423

and I see the date column in the GRID as "null".

If change the datasource schema model to string, then sorting works fine:
                    date:{ type:"string" },


5 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 26 Apr 2012, 03:44 PM
Hi Yechezkal,

The date handling has changed in the new official release. As a workaround for your case, I would suggest to define a custom parser for the date field and convert the string received by the server into a valid JavaScript date object. In this jsFiddle example you can see this approach in action.

All the best,
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
Dr.YSG
Top achievements
Rank 2
answered on 26 Apr 2012, 03:50 PM
I rather do the work on the server, (Windows 7, WCF, JSON). Are there any of the .NET DateTime formats that I could use that would be understood by your standard JSON date parser, so that I don't have to do all this work in the client?

 (some of my tables are approaching 5K records).
0
Dr.YSG
Top achievements
Rank 2
answered on 04 May 2012, 04:11 PM
I'd rather not use a custom parser. Is there something I can do on the server side to make the .NET DataTime format directly understandable by your JSON parser?

0
Accepted
Alexander Valchev
Telerik team
answered on 07 May 2012, 04:21 PM
Hello Yechezkal,

The .NET date time formats that are using milliseconds ("\/Date(1234656000000)\/" ,"/Date(1245398693390)/" ) are automatically parsed to JavaScript date objects.
I updated my previous example to show this functionality in action.

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
Dr.YSG
Top achievements
Rank 2
answered on 07 May 2012, 08:16 PM
This is working great. And for future readers, let me tell that WCF will serialize to JSON if you say:

        [WebGet(ResponseFormat = WebMessageFormat.Json)]
        YourReturnStructure myMethod();

and DateTimes are encoded with timeZone offset:

"date":"\/Date(949381200000-0500)\/",
but that is no problem if you specify in your datasource:                     date:{ type:"date" }, and then in your grid you can reformat to your favorite style:                 field:"date",
                format: "{0:dd-MMM-yyyy H:m:ss}",
                width:170  


Tags
Data Source
Asked by
Dr.YSG
Top achievements
Rank 2
Answers by
Alexander Valchev
Telerik team
Dr.YSG
Top achievements
Rank 2
Share this question
or