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

Best practice for modeling collection properties

1 Answer 76 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Brett
Top achievements
Rank 2
Brett asked on 20 Dec 2012, 07:18 PM
Hello all,

I am struggling with the best way to model collection properties for a kendo.data.Model used in a kendo.data.DataSource, and configure it is such a way that data-bind attributes understand. For example, say my view model looks like this:

var entityModel = kendo.data.Model.define({
  id: 'Id',
  fields: {
    Id: { editable: false, defaultValue: '00000000' },
    Name: {},
    Created: { type: 'date' },
    Contract: {
      StartDate: { type: 'date' },
      EndDate: { type: 'date' },
      Received: { type: 'date' }
    },
    Vendor: {
      Name: {},
      Street: {},
      City: {},
      State: {},
      Zip: {},
      Phone: {},
      Email: {}
    },
    Invoices: []
  }
});
 
var entityDataSource = new kendo.data.DataSource({
  schema: {
    model: entityModel
  },
  transport: {
    ...
  }
});

As you can see, the Invoices property is an array - a collection of invoices. How do I get the DataSource to understand this, and how would I bind Invoices to the view? Would this work?
<div data-template="invoiceTemplate" data-bind="source: Invoices"></div>
What if I wanted to represent this collection of Invoices as a kendoGrid which I could add, edit, and delete from? Is this functionality supported out-of-the-box or will I need to create a separate Invoice DataSource?

Thanks for any assistance you can provide.

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 24 Dec 2012, 12:13 PM
Hi Brett,

 This functionality is currently not supported out of the box. A model field can only be of a primitive JavaScript type - String, Number or Date.

 If you want to display a master/detail grid you need a separate data source for the detail grid. You can check the following demo for further details: http://demos.kendoui.com/web/grid/detailtemplate.html

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
Data Source
Asked by
Brett
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Share this question
or