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

Custom server request handing for Datasource

1 Answer 7 Views
Data Source
This is a migrated thread and some comments may be shown as answers.
Ankita
Top achievements
Rank 1
Ankita asked on 10 Dec 2018, 11:38 AM

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

We have a defined url here so the data is requested from this single URL and stored.

In my use-case, I need to make 3 sequential server calls before I get the actual data.

That is why I need to intercept the read  function of transport where I can make all the necessary backend calls and combine the results to move forward.

 

1 Answer, 1 is accepted

Sort by
0
Dimitar
Telerik team
answered on 12 Dec 2018, 06:52 AM
Hello Ankita,

The Kendo UI dataSource's read can be defined as a function in order to achieve the desired result:
<script>
var dataSource = new kendo.data.DataSource({
  transport: {
    read: function(options) {
      // make JSONP request to https://demos.telerik.com/kendo-ui/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);
        }
      });
    }
  }
});
</script>

Also, important to note is that all transport actions (read, update, create, destroy) must be defined in the same way, that is, as functions or as objects. Otherwise, mixing the different configuration alternatives might lead to undesired side effects and is generally not recommended.

In addition to the above, you can find additional information regarding configuring a custom read in the following article:


Regards,
Dimitar
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Data Source
Asked by
Ankita
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Share this question
or