JSON date handling changed in latest release?

6 posts, 1 answers
  1. Dr.YSG
    Dr.YSG avatar
    210 posts
    Member since:
    Dec 2009

    Posted 23 Apr 2012 Link to this post

    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" },


  2. Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 26 Apr 2012 Link to this post

    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!
  3. Kendo UI is VS 2017 Ready
  4. Dr.YSG
    Dr.YSG avatar
    210 posts
    Member since:
    Dec 2009

    Posted 26 Apr 2012 Link to this post

    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).
  5. Dr.YSG
    Dr.YSG avatar
    210 posts
    Member since:
    Dec 2009

    Posted 04 May 2012 Link to this post

    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?

  6. Answer
    Alexander Valchev
    Admin
    Alexander Valchev avatar
    2875 posts

    Posted 07 May 2012 Link to this post

    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!
  7. Dr.YSG
    Dr.YSG avatar
    210 posts
    Member since:
    Dec 2009

    Posted 07 May 2012 Link to this post

    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  


Back to Top
Kendo UI is VS 2017 Ready