Populate another Datasource from within first!

5 posts, 1 answers
  1. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 18 Feb 2015 Link to this post

    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
        }
    })


  2. Sherman
    Sherman avatar
    2 posts
    Member since:
    May 2011

    Posted 19 Feb 2015 in reply to Bilal Link to this post

    Can you not use a promise from datasource A to then update datasource B?

    $(function() {
        datasourceA.read().then(
    function() {
            datasourceB.read();
        });
    });
  3. Kendo UI is VS 2017 Ready
  4. Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 20 Feb 2015 Link to this post

    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!
     
  5. Bilal
    Bilal avatar
    109 posts
    Member since:
    Oct 2014

    Posted 20 Feb 2015 in reply to Petyo Link to this post

    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
  6. Answer
    Petyo
    Admin
    Petyo avatar
    2439 posts

    Posted 24 Feb 2015 Link to this post

    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!
     
Back to Top
Kendo UI is VS 2017 Ready