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

Trying to understand the DataSource

3 Answers 52 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 29 Aug 2012, 03:29 PM
Hi,

We are really struggeling to get the DataSource working the way we want it. We are building a PoC with Kendo UI Complete. We've created a ViewModel that looks like this:

[DataContract]
    public partial class VMProject : VMRoot
    {
        public VMProject() {}
 
        public static VMProject GetById(object sender, int id)
        {
            return CallGetVMById<VMProject>("", id);
        }
 
        public static VMEntitySet<VMProject> AllVMProjectList(object sender)
        {
            return (VMEntitySet<VMProject>)CallGetVMAllList<VMEntitySet<VMProject>>(sender);
        }
 
        [DataMember]
        public String Name
        {
            get { return CallGetData<String>("Name"); }
            set { CallSetData ("Name", value); }
        }
 
        [DataMember]
        public VMEntitySet<VMProjectRegel> ProjectRegelList
        {
            get { return CallGetData<VMEntitySet<VMProjectRegel>>("ProjectRegelList"); }
            // set  { CallSetData ("ProjectRegelList", value); }
        }
 
    }

The consumed class VMRoot looks like this:
[DataContract]
    public partial class VMRoot : Viewmodel
    {
        public VMRoot() {}
 
        public static VMRoot GetById(object sender, int id)
        {
            return CallGetVMById<VMRoot>("", id);
        }
 
        public static VMEntitySet<VMRoot> AllVMRootList(object sender)
        {
            return (VMEntitySet<VMRoot>)CallGetVMAllList<VMEntitySet<VMRoot>>(sender);
        }
 
        [DataMember]
        public Int32 Id
        {
            get { return CallGetData<Int32>("Id"); }
            set { CallSetData ("Id", value); }
        }
 
        [DataMember]
        public DateTime CreatedOn
        {
            get { return CallGetData<DateTime>("CreatedOn"); }
            set { CallSetData ("CreatedOn", value); }
        }
 
        [DataMember]
        public Int32 CreatedBy
        {
            get { return CallGetData<Int32>("CreatedBy"); }
            set { CallSetData ("CreatedBy", value); }
        }
 
        [DataMember]
        public DateTime ChangedOn
        {
            get { return CallGetData<DateTime>("ChangedOn"); }
            set { CallSetData ("ChangedOn", value); }
        }
 
        [DataMember]
        public Int32 ChangedBy
        {
            get { return CallGetData<Int32>("ChangedBy"); }
            set { CallSetData ("ChangedBy", value); }
        }
 
    }

The VMEntitySet is an ObservableCollection which contains VMProjectRegel objects. These are defined like so:
    [DataContract]
    public partial class VMProjectRegel : VMRoot
    {
        public VMProjectRegel() {}
 
        public static VMProjectRegel GetById(object sender, int id)
        {
            return CallGetVMById<VMProjectRegel>("", id);
        }
 
        public static VMEntitySet<VMProjectRegel> AllVMProjectRegelList(object sender)
        {
            return (VMEntitySet<VMProjectRegel>)CallGetVMAllList<VMEntitySet<VMProjectRegel>>(sender);
        }
 
        [DataMember]
        public Int32 Aantal
        {
            get { return CallGetData<Int32>("Aantal"); }
            set { CallSetData ("Aantal", value); }
        }
 
        [DataMember]
        public Decimal Prijs
        {
            get { return CallGetData<Decimal>("Prijs"); }
            set { CallSetData ("Prijs", value); }
        }
 
        [DataMember]
        public Decimal BTW
        {
            get { return CallGetData<Decimal>("BTW"); }
            set { CallSetData ("BTW", value); }
        }
 
    }

We have defined the Model like so:
var Project = kendo.data.Model.define(
{
    id: "Id",
    fields:
    {
        DatumAanvang:
        {
            type: "date"
        },
        DatumFaktuur:
        {
            type: "date"
        },
        Name:
        {
            type: "string"
        },
        CreatedOn:
        {
            "type": "date"
        },
        CreatedBy:
        {
            "type": "number"
        },
        ChangedOn:
        {
            "type": "date"
        },
        ChangedBy:
        {
            "type": "number"
        }
    }
});

And the DataSource like so:

var dataSourceprojecten = new kendo.data.DataSource(
            {
                // the transport tells the datasource what endpoints
                // to use for CRUD actions
                schema:
                {
                    model: Project
                },
                transport:
                {
                    read:
                    {
                        url: "../api/projectonderhoud/get",
                        dataType: "json"
                    }
                }
            });

The JSON we receive looks like this:
[
  {
    "DatumAanvang": "\/Date(1345732135057+0200)\/",
    "DatumFaktuur": "\/Date(1345732135059+0200)\/",
    "Name": "Project onderhoud",
    "ProjectRegelList": [
      {
        "Aantal": 99,
        "Prijs": 99.000000000000,
        "BTW": 1.000000000000,
        "Id": 101,
        "CreatedOn": "\/Date(1345732135085+0200)\/",
        "CreatedBy": 10,
        "ChangedOn": "\/Date(1345732135085+0200)\/",
        "ChangedBy": 10
      }
  ],
    "Id": 1,
    "CreatedOn": "\/Date(1345732135060+0200)\/",
    "CreatedBy": 10,
    "ChangedOn": "\/Date(1345732135060+0200)\/",
    "ChangedBy": 10
  }
]

If I let the code run it results in HTML that shows the wrong Date format for the CreatedOn date. When however I specify the Model in the DataSource like so:

var dataSourceprojecten = new kendo.data.DataSource(
{
    // the transport tells the datasource what endpoints
    // to use for CRUD actions
    schema:
    {
        model:
        {
            id: "Id",
            fields:
            {
                DatumAanvang:
                {
                    type: "date"
                },
                DatumFaktuur:
                {
                    type: "date"
                },
                Name:
                {
                    type: "string"
                },
                CreatedOn:
                {
                    "type": "date"
                },
                CreatedBy:
                {
                    "type": "number"
                },
                ChangedOn:
                {
                    "type": "date"
                },
                ChangedBy:
                {
                    "type": "number"
                }
            }
        }
    },
    transport:
    {
        read:
        {
            url: "../api/projectonderhoud/get",
            dataType: "json"
        }
    }
});

Now the date is shown correctly. I just don't understand why the defined Model is not seen by the DataSource and the model defenition inside the DataSource is seen.

Regards
Paul

3 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 30 Aug 2012, 08:40 AM
Hello Paul,

 This is due to a known bug which has been fixed and will be official with the upcoming service pack. You can use the inline model definition as a workaround.

Greetings,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Paul
Top achievements
Rank 1
answered on 30 Aug 2012, 12:12 PM
Hi Atanas,

How soon can we expect the Service Pack to arrive?

Regard
Paul
0
Atanas Korchev
Telerik team
answered on 30 Aug 2012, 12:24 PM
Hi,

 The service pack will be available in Mid September. Please have in mind that it is available only to commercial license holders.

Regards,
Atanas Korchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
General Discussions
Asked by
Paul
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Paul
Top achievements
Rank 1
Share this question
or