How does the DataSource.Transport.Read property populate the datasource when Read is set as a function

5 posts, 1 answers
  1. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 12 Nov 2013 Link to this post

    In the example below, taken from the Kendo site, how does the dataSource itself get populated? 
    var dataSource = new kendo.data.DataSource({
      transport: {
        read: function(options) {
          // make JSONP request to http://demos.kendoui.com/service/products
          $.ajax({
            dataType: "jsonp", // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
            success: function(result) {
              // notify the data source that the request succeeded
              options.success(result);
            },
            error: function(result) {
              // notify the data source that the request failed
              options.error(result);
            }
          });
        }
      }
    });
    dataSource.fetch(function() {
      console.log(dataSource.view().length); // displays "77"
    });
    Nothing in this example seems to indicate how the data source would get populate if the ajax call succeeds? 
  2. Answer
    Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 13 Nov 2013 Link to this post

    Hi Jacques,

     Perhaps you've missed the following code:

            success: function(result) {
              // notify the data source that the request succeeded
              options.success(result);
            }

    As the comment says calling the success function notifies the data source that the ajax request has succeeded.

    Regards,
    Atanas Korchev
    Telerik
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
  3. Jacques
    Jacques avatar
    135 posts
    Member since:
    Jun 2007

    Posted 13 Nov 2013 Link to this post

    Hi Atanas, 

    "As the comment says calling the success function notifies the data source that the ajax request has succeeded."

    Sure it says that it "notifies" the data source that the ajax request succeeded, but do we then assume that options.success(result) is also passing the resulting data to the dataSource? Notifying and populating data seem like two different things, but if you say that the success method/function does exactly that, then I'm happy? 

    Thanks for the answer.
  4. Saranya
    Saranya avatar
    11 posts
    Member since:
    Apr 2013

    Posted 05 Jan in reply to Atanas Korchev Link to this post

    I have implemented this and am successfully reading and setting the results on success. However, this is causing the transport read method to trigger again. What would cause this?

    When I set a break point and follow the stack trace it shows that options.success(result); is triggering the read function call to generate another ajax request.

    I do not have any dataBound, binding, etc. events initialized.

    In the demo Set Read as a Function, I cannot replicate the issue
    http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-transport.read

  5. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1823 posts

    Posted 09 Jan Link to this post

    Hello Saranya,

    I already replied in one of your support threads that we are not aware of such problem. We would need a sample dojo example which replicates this problem in order to perform investigation. 

    Regards,
    Boyan Dimitrov
    Telerik by Progress
    Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Back to Top