Transport
configurationThe configuration used to load and save the data items. A data source is remote or local based on the way it retrieves data items.
Remote data sources load and save data items from and to a remote end-point (also known as remote service or server). The transport option describes the remote service configuration - URL, HTTP verb, HTTP headers, and others. The transport option can also be used to implement custom data loading and saving.
Local data sources are bound to a JavaScript array via the data option.
transport
Objecttransport.batch
ObjectConfigurable for the odata-v4 data source
typeinbatchmode.
The object can contain all the available jQuery.ajax options.
transport.cache
BooleanSpecifies if the transport caches the result from read requests. The query parameters are used as a cache key and if the key is present in the cache, a new request to the server is not executed. The cache is kept in memory and, thus, cleared on page refresh.
Default: false
transport.create
Object|String|FunctionThe configuration used when the data source saves newly created data items. Those are items added to the data source via the add or insert methods.
The data source uses
jQuery.ajaxto make an HTTP request to the remote service. The value configured viatransport.createis passed tojQuery.ajax. This means that you can set all options supported byjQuery.ajaxviatransport.createexcept thesuccessanderrorcallback functions which are used by the transport.
If the value of transport.create is a function, the data source invokes that function instead of jQuery.ajax. Check the jQuery documentation for more details on the provided argument.
If the value of transport.create is a string, the data source uses this string as the URL of the remote service.
- The remote service must return the inserted data items and the data item field configured as the
idmust be set. For example, if theidof the data item isProductID, the"create"server response must be[{ "ProductID": 79, "AnotherProperties": "value"}]including the ID and the other properties of the data items.- All transport actions (read, update, create, destroy) must be defined in the same way, that is, as functions or as objects. Mixing the different configuration alternatives is not possible.
transport.destroy
Object|String|FunctionThe configuration used when the data source destroys data items. Those are items removed from the data source via the remove method.
The data source uses
jQuery.ajaxto make an HTTP request to the remote service. The value configured viatransport.destroyis passed tojQuery.ajax. This means that you can set all options supported byjQuery.ajaxviatransport.destroyexcept thesuccessanderrorcallback functions which are used by the transport.
If the value of transport.destroy is a function, the data source invokes that function instead of jQuery.ajax.
If the value of transport.destroy is a string, the data source uses this string as the URL of the remote service.
All transport actions (read, update, create, destroy) must be defined in the same way, that is, as functions or as objects. Mixing the different configuration alternatives is not possible.
transport.parameterMap
FunctionThe function which converts the request parameters to a format suitable for the remote service. By default, the data source sends the parameters using jQuery conventions.
- The
parameterMapmethod is often used to encode the parameters in JSON format.- The
parameterMapfunction will not be called when using custom functions for the read, update, create, and destroy operations.
If a transport.read.data function is used together with parameterMap, remember to preserve the result from the data function that will be received in the parameterMap arguments. An example is provided below. Generally, the parameterMap function is designed to transform the request payload, not to add new parameters to it.
transport: {
read: {
url: "my-data-service-url",
data: function () {
return {
foo: 1
};
}
},
parameterMap: function (data, type) {
// if type is "read", then data is { foo: 1 }, we also want to add { "bar": 2 }
return kendo.stringify($.extend({ "bar": 2 }, data));
}
}
The parameters which will be sent to the remote service. The value specified in the data field of the transport settings (create, read, update or destroy) is included as well. If batch is set to false, the fields of the changed data items are also included.
The current aggregate configuration as set via the aggregate option. Available if the serverAggregates option is set to true and the data source makes a "read" request.
The current grouping configuration as set via the group option. Available if the serverGrouping option is set to true and the data source makes a "read" request.
The current filter configuration as set via the filter option. Available if the serverFiltering option is set to true and the data source makes a "read" request.
All changed data items. Available if there are any data item changes and the batch option is set to true.
The current page. Available if the serverPaging option is set to true and the data source makes a "read" request.
The current page size as set via the pageSize option. Available if the serverPaging option is set to true and the data source makes a "read" request.
The number of data items to skip. Available if the serverPaging option is set to true and the data source makes a "read" request.
The current sort configuration as set via the sort option. Available if the serverSorting option is set to true and the data source makes a "read" request.
The number of data items to return (the same as data.pageSize). Available if the serverPaging option is set to true and the data source makes a "read" request.
The type of the request which the data source makes.
The supported values are:
"create""read""update""destroy"
—The request parameters converted to a format required by the remote service.
transport.push
FunctionThe function invoked during transport initialization which sets up push notifications. The data source will call this function only once and provide callbacks which will handle push notifications (data pushed from the server).
An object containing callbacks for notifying the data source of push notifications.
A function that should be invoked to notify the data source about newly created data items that are pushed from the server. Accepts a single argument - the object pushed from the server which should follow the schema.data configuration.
A function that should be invoked to notify the data source about destroyed data items that are pushed from the server. Accepts a single argument - the object pushed from the server
which should follow the schema.data configuration.
A function that should be invoked to notify the data source about updated data items that are pushed from the server. Accepts a single argument - the object pushed from the server
which should follow the schema.data configuration.
transport.read
Object|String|FunctionThe configuration used when the data source loads data items from a remote service.
The data source uses
jQuery.ajaxto make an HTTP request to the remote service. The value configured viatransport.readis passed tojQuery.ajax. This means that you can set all options supported byjQuery.ajaxviatransport.readexcept thesuccessanderrorcallback functions which are used by the transport.
If the value of transport.read is a function, the data source invokes that function instead of jQuery.ajax.
If the value of transport.read is a string, the data source uses this string as the URL of the remote service.
All transport actions (read, update, create, destroy) must be defined in the same way, that is, as functions or as objects. Mixing the different configuration alternatives is not possible.
transport.signalr
ObjectThe configuration used when type is set to "signalr". Configures the SignalR settings - hub, connection promise, server, and client hub methods.
A live demo is available at demos.telerik.com/kendo-ui.
It is recommended to get familiar with the SignalR JavaScript API and ASP.NET Core SignalR.
transport.submit
FunctionA function that will handle create, update and delete operations in a single batch when custom transport is used, that is, the transport.read is defined as a function.
The transport.create, transport.update, and transport.delete operations will not be executed in this case.
<div id="grid"></div>
<script>
var dataSource = new kendo.data.DataSource({
transport: {
read: function(e) {
// Custom read implementation
$.ajax({
url: "/api/data",
success: function(result) {
e.success(result);
}
});
},
submit: function(e) {
// Handle all CRUD operations in batch
var models = e.data.models;
var operations = [];
for (var i = 0; i < models.length; i++) {
var model = models[i];
if (model.isNew()) {
operations.push({ type: "create", data: model });
} else if (model.dirty) {
operations.push({ type: "update", data: model });
}
}
// Send batch operations to server
$.ajax({
url: "/api/batch",
type: "POST",
data: JSON.stringify(operations),
contentType: "application/json",
success: function() {
e.success();
}
});
}
}
});
$("#grid").kendoGrid({
dataSource: dataSource,
editable: true
});
</script>
This function will only be invoked when the DataSource is in its batch mode.
An object containing the created (e.data.created), updated (e.data.updated), and destroyed (e.data.destroyed) items.
A callback that should be called for each operation with two parameters - items and operation. See example below.
A callback that should be called in case of failure of any of the operations.
transport.update
Object|String|FunctionThe configuration used when the data source saves updated data items. Those are data items whose fields have been updated.
The data source uses
jQuery.ajaxto make an HTTP request to the remote service. The value configured viatransport.updateis passed tojQuery.ajax. This means that you can set all options supported byjQuery.ajaxviatransport.updateexcept thesuccessanderrorcallback functions which are used by the transport.
If the value of transport.update is a function, the data source invokes that function instead of jQuery.ajax.
If the value of transport.update is a string, the data source uses this string as the URL of the remote service.
All transport actions (read, update, create, destroy) must be defined in the same way, that is, as functions or as objects. Mixing the different configuration alternatives is not possible.