Hi,
A seconde question about the DataSource is how can we get the Data of a subset into f.i. a grid. Here's the code we use for our JSON services.
The consumed class VMRoot looks like this:
The VMEntitySet is an ObservableCollection which contains VMProjectRegel objects. These are defined like so:
The JSON we receive looks like this:
The DataSource is defined like so:
after executing the dataSourceprojecten.read() the data is available for the main list but how do we specify the fetch for the ProjectRegelsList in f.i. a grid?
This is what I have tried (among many other attempts) to get it to work:
Regards
Paul
A seconde question about the DataSource is how can we get the Data of a subset into f.i. a grid. Here's the code we use for our JSON services.
[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); } } }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 }]The DataSource is defined 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" } }});after executing the dataSourceprojecten.read() the data is available for the main list but how do we specify the fetch for the ProjectRegelsList in f.i. a grid?
This is what I have tried (among many other attempts) to get it to work:
$("#projectregels").kendoGrid( { dataSource: { schema: { model: ProjectRegel }, data: dataSourceprojecten.ProjectRegelList }, groupable: true, sortable: true, pagesize: 10, columns: [ { field: "Id", title: "Id" }, { field: "Aantal", title: "Aantal" }, { field: "Prijs" }, { field: "BTW" }, { field: "CreatedOn", title: "Created on", template: '#= kendo.toString(CreatedOn,"dd MM yyyy") #' }, { field: "CreatedBy" } ] });Regards
Paul