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

Nested / combined datasources

1 Answer 209 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
cra
Top achievements
Rank 1
cra asked on 18 Dec 2015, 08:19 PM

Hello all,

 

Is it possible to created a nested datasource or at least is there a general best practice for combining multiple datasources? Here is my scenario:

 

I have an API that exposes some data for an object, a house for instance. A house has various propeties: rooms, bathrooms, etc. For a particular module in our client application we are "searching" for a specific object using an AutoComplete. Once the specific object is view is displayed with the detailed information about the house. In addition in this specific view some additional data is needed, which currently we are combining into one large response object all at once. However it seems that this breaks one of the fundamentals of a RESTful API in that now our /Houses endpoint returns all this related data that is sometimes needed but not always. I have also read that even allowing for related data to be dynamically included at the request of the client information is considered "barely acceptable" which leaves the other option being to make several (4 total in my scenario) requests. Which I have no problem doing in interest of keeping our API "pure". However I would rather not have to "monitor" the completion of each datasource independently then display the form once the last of the datasources has completed. Is there a way to combine the results of my datasources? Could I simply create an observable array that keeps a reference to each datasource?

 

Any ideas on this topic would be greatly appreciated.

1 Answer, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 23 Dec 2015, 08:52 AM
Hi,

I would recommend to use separate dataSource instances as the dataSource component is designed to work with flat data structures. You may use the filter method and serverFiltering to request data which matches given criteria.

There is no straightforward way to combine the result of multiple DataSources. Generally speaking you may retrieve the data array of each DataSource instance through the data method and combine them into one array but updating the array would require a lot of code.

Could I simply create an observable array that keeps a reference to each datasource?

Not exactly, the DataSource's data is an observable array but if you build an array from it, this array will not automatically update when DataSource is refreshed.

Regards,
Alexander Valchev
Telerik
 
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
cra
Top achievements
Rank 1
Answers by
Alexander Valchev
Telerik team
Share this question
or