For some reason KendoUI DataSource does not allow to access current ajax request. Indeed, it seems quite natural to have a way to cancel running request.
To achieve a desired effect we have made a small set of changes in the RemoteTransport class:
RemoteTransport
var RemoteTransport_setup = kendo.RemoteTransport.fn.setup; kendo.RemoteTransport.fn.setup = function() { var that = this, options = RemoteTransport_setup.apply(that, arguments), beforeSend = options.beforeSend; options.beforeSend = functions(request, options) { that.abort(); that._request = request; if (beforeSend && (beforeSend.apply(this, arguments) === false)) { that._request = null; return false; } request.always(function() { that._request = null; }); } return options; } kendo.RemoteTransport.fn.request = function() { return this._request; } kendo.RemoteTransport.fn.abort = function() { var request = this._request; if (request) { this._request = null; request.abort(); } }
var RemoteTransport_setup = kendo.RemoteTransport.fn.setup;
kendo.RemoteTransport.fn.setup = function() { var that = this, options = RemoteTransport_setup.apply(that, arguments), beforeSend = options.beforeSend; options.beforeSend = functions(request, options) { that.abort(); that._request = request; if (beforeSend && (beforeSend.apply(this, arguments) === false)) { that._request = null; return false; } request.always(function() { that._request = null; }); } return options; } kendo.RemoteTransport.fn.request = function() { return this._request; } kendo.RemoteTransport.fn.abort = function() { var request = this._request; if (request) { this._request = null; request.abort(); } }
These changes allow to get an ajax request instance: grid.dataSource.request(), or to cancel a request grid.dataSource.abort().
grid.dataSource.request()
grid.dataSource.abort()
Remember Me
a@href@title, b, blockquote@cite, em, i, strike, strong, sub, super, u