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

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

4 Answers 133 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Jacques
Top achievements
Rank 2
Jacques asked on 13 Nov 2013, 04:57 AM
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? 

4 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 13 Nov 2013, 07:51 AM
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!
0
Jacques
Top achievements
Rank 2
answered on 13 Nov 2013, 07:55 AM
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.
0
Saranya
Top achievements
Rank 1
answered on 05 Jan 2017, 09:48 PM

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

0
Boyan Dimitrov
Telerik team
answered on 09 Jan 2017, 12:06 PM

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.
Tags
Data Source
Asked by
Jacques
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
Jacques
Top achievements
Rank 2
Saranya
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or