Cancel a transport read request mid-flight

1 Answer 466 Views
Data Source
Alon
Top achievements
Rank 1
Veteran
Alon asked on 03 Oct 2021, 02:02 PM

We have defined a new data source which executes a $.ajax to retrieve some data from a remote server.

return new kendo.data.DataSource({
    pageSize: 10,
    serverPaging: true,
    serverSorting: true,
    serverFiltering: true,
    type: "json",
    sort: {
      field: "name",
      dir: "asc"
    },
    transport: {
      read: function (options) {}....

Now lets consider the following scenario:

The read function is triggered and the call is made to the server but the server is being slow. In the meantime a new read request needs to be made and we want to abort the current read request and issue a new one. 

Using vanilla Jquery we just do something like 

myAjaxRequest.abort()

However, I can not seem to find a similar method to abort a read request (or any request) in the Kendo Data Source Object.

Are you able to offer a solution?

1 Answer, 1 is accepted

Sort by
1
Dimitar
Telerik team
answered on 06 Oct 2021, 10:52 AM

The Kendo UI DataSource ajax read requests may be aborted through the ajax abort() method, followed by a success or error response from the server. The response notifies the DataSource that the respective request has finished and it may initiate a new request. This Dojo snippet shows the suggested approach. And the following Dojo snippet shows how to save the success function in a variable and then call it after the request is aborted, when clicking the Filter button multiple times in a row. In this example it is important to note the format of the parameters passed to the success function - this is the expected format when the schema is set.

Regards,
Dimitar
Progress Telerik

Remote troubleshooting is now easier with Telerik Fiddler Jam. Get the full context to end-users' issues in just three steps! Start your trial here - https://www.telerik.com/fiddler-jam.
Alon
Top achievements
Rank 1
Veteran
commented on 06 Oct 2021, 06:49 PM

Thanks Dimitar.

The Dojo Snippet is very helpful. Is there some where where we can vote on this enhancement? It would be nice to be able to call a method called abortReadRequest() (or something like that) and have the DataSource cancel the request.

Regards,

Alon

Dimitar
Telerik team
commented on 07 Oct 2021, 05:59 AM

I am glad the suggested approach is helpful. A Feature Request item may be proposed at the Kendo UI for jQuery Feedback Portal. It will gain votes and its implementation will be prioritized based on them.

Regards,
Dimitar

Tags
Data Source
Asked by
Alon
Top achievements
Rank 1
Veteran
Answers by
Dimitar
Telerik team
Share this question
or