Edit this page

fetch

Reads the data items from a remote service (if the transport option is set) or from a JavaScript array (if the data option is set).

The fetch method makes a request to the remote service only the first time it is called if the dataSource is not configured for server operations.

Parameters

callback Function (optional)

The optional function which is executed when the remote request is finished. The function context (available via the this keyword) will be set to the data source instance.

Returns

Promise A promise that will be resolved when the data has been loaded, or rejected if an HTTP error occurs.

Example - read data from a remote data source

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read:  {
      url: "https://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
    }
  }
});
// read the data items from https://demos.telerik.com/kendo-ui/service/products
dataSource.fetch(function(){
  var data = this.data();
  console.log(data.length);  // displays "77"
  console.log(data[0].ProductName); // displays "Chai"
});
</script>

Example - use the Promise API to track when a request finishes

<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read:  {
      url: "https://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp"
    }
  }
});

// read the data items from https://demos.telerik.com/kendo-ui/service/products
dataSource.fetch().then(function(){
  var data = dataSource.data();
  console.log(data.length);  // displays "77"
  console.log(data[0].ProductName); // displays "Chai"
});
</script>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy