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

Add collection to DataSource as JSON

1 Answer 161 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 01 Jun 2012, 05:55 PM
I've been racking my brain for several days trying to figure out a way to add an entire JSON collection to a DataStore without iterating through the JSON collection and calling .add for all the items.

Is there a way to do this?

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 04 Jun 2012, 02:00 PM
Hi Anthony,

The add method accepts an object (single model) as a parameter, the data method on the other hand operates with arrays. To pass an entire JSON collection to the dataSource you can try the following:
var sampleData = [{"foo": 10, "bar": 10}, {"foo": 11, "bar": 11}]
 
dataSource.data(sampleData);

Please have in mind that this approach replaces the whole data set with a new one, e.g. does not add/insert new records.

Greetings,
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!
Tags
Data Source
Asked by
Anthony
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or