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

Populate another Datasource from within first!

4 Answers 164 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Bilal
Top achievements
Rank 2
Bilal asked on 18 Feb 2015, 11:57 AM
Hi,
I have a view model with two Data Sources A & B.

- Data Source A requests data from server. Data received contains multi-collections.
- One collection is returned from the "Parse" function to populate Data Source A
- Another collection is being set to a JavaScript variable to be used later on by Data Source B. Why? I couldn't access current view model to set the value of the other Data Source.

Problem now is, when the page loads, the local collection is empty and Data Source B is defined based on that local collection. By the time the data received by Data Source A, the form would have been bound to empty data.

Is there a work around in here?

signatures is a local array outside view model that is being updated by Data Source A parse function.

signatureDatasource: new kendo.data.DataSource({
    data: function() { return signatures },
    schema: {
        model: SignatureModel
    }
})


4 Answers, 1 is accepted

Sort by
0
Sherman
Top achievements
Rank 1
answered on 19 Feb 2015, 07:24 PM
Can you not use a promise from datasource A to then update datasource B?

$(function() {
    datasourceA.read().then(
function() {
        datasourceB.read();
    });
});
0
Petyo
Telerik team
answered on 20 Feb 2015, 08:01 AM
Hello,

Problem now is, when the page loads, the local collection is empty and Data Source B is defined based on that local collection. By the time the data received by Data Source A, the form would have been bound to empty data.

If I understand you correctly, you are trying to avoid that behavior. Can you please elaborate on the alternative which would fit your project requirements? Thank you in advance.

Regards,
Petyo
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
Bilal
Top achievements
Rank 2
answered on 20 Feb 2015, 08:18 AM
Hi Petyo,

I might be "misusing" the Data Source in a sense that I am returning multiple sets of data from server. However, in the parse function I return whatever data needed by Data Source to bind to Grid. The rest I am currently populating them as follows:

if ( e.signatures ) {
    viewmodel.get("signatureDatasource").data(e.signatures);
}

At first the "signatureDatasource" is empty, but then it gets populated.

The aforementioned Data Source is used to populate a Drop Down List, so it is not major and essential to be shown when page loads.

How do you find this solution?

Best regards
Bilal Haidar
0
Accepted
Petyo
Telerik team
answered on 24 Feb 2015, 07:53 AM
Hello Bilal,

in case this solution is applicable to your project, feel free to implement it. 

Regards,
Petyo
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
Bilal
Top achievements
Rank 2
Answers by
Sherman
Top achievements
Rank 1
Petyo
Telerik team
Bilal
Top achievements
Rank 2
Share this question
or