Model, DataSource and Date

1 posts, 0 answers
  1. Luc
    Luc avatar
    1 posts
    Member since:
    Aug 2012

    Posted 20 Nov 2012 Link to this post

    Hello,

    I'm trying to user the kendo.data.Model to make an observable object from a single object retrieved from a web service.
    When I do a kendo.data.Model.define(...), the fields are entirely ignored, and the field containing the date is mapped to a string.

    If I create a datasource with the exact same model, I retrieve a correct date.

    I tried to put a custom parse function, and in the first case, nothing happen.
    In the second scenario, I can see my parse method called.

    Here is a sample of what I do :
    var obj = {
        Id: "1",
        Name: "foo",
        Age: "28",
        Fire: "/Date(1348479856993)/"
    };
     
    var objModel = kendo.data.Model.define({
        id: "Id",
        fields: {
            Id: { type: "number" },
            Name: { type: "string", parse: function(e) {
                    debugger;
                    return e;
                }
            },
            Fire: { type: "date" },
            Age: { type: "number" }
        }
    });
     
    var obj1 = new objModel(obj);
    console.log(obj1.get("Fire"));
     
    var dataSource = new kendo.data.DataSource({
        data: [ obj ],
        schema: {
            model: {
                id: "Id",
                fields: {
                    Id: { type: "number" },
                    Name: { type: "string", parse: function(e) {
                        debugger;
                        return e;
                    }
                },
                    Fire: { type: "date" },
                    Age: { type: "number" }
                }
            }
        }
    });
    dataSource.read();
    var obj2 = dataSource.at(0);
    console.log(obj2.get("Fire"));
    This make the following output to the console :
    /Date(1348479856993)/
    Mon Sep 24 2012 11:44:16 GMT+0200 (Romance Daylight Time)

    Thanks for you help.
Back to Top