Schema
configurationThe configuration used to parse the remote service response.
schema
Objectschema.aggregates
Function|StringThe field from the response which contains the aggregate results. Can be set to a function which is called to return the aggregate results from the response.
The
aggregatesoption is used only when theserverAggregatesoption is set totrue.
The result of the function should be a JavaScript object which contains the aggregate results for every field in the following format:
{
Field1Name: {
Function1Name: Function1Value,
Function2Name: Function2Value
},
Field2Name: {
Function1Name: Function1Value
}
}
For example, if the data source is configured like this:
var dataSource = new kendo.data.DataSource({
transport: {
/* transport configuration */
},
serverAggregates: true,
aggregate: [
{ field: "unitPrice", aggregate: "max" },
{ field: "unitPrice", aggregate: "min" },
{ field: "ProductName", aggregate: "count" }
]
});
The aggregate results should have the following format:
{
unitPrice: {
max: 100,
min: 1
},
productName: {
count: 42
}
}
schema.data
Function|StringThe field from the server response which contains the data items. Can be set to a function which is called to return the data items for the response.
The
dataoption will not be used if the data source is grouped and set forserverGrouping.
—The data items from the response.
schema.errors
Function|StringThe field from the server response which contains server-side errors. Can be set to a function which is called to return the errors for response. If there are any errors, the error event will be fired.
<div id="grid"></div>
<script>
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://demos.telerik.com/service/error-response",
dataType: "json"
}
},
schema: {
data: "data",
errors: "errors"
},
error: function(e) {
console.log("Error occurred: " + e.errors);
}
});
$("#grid").kendoGrid({
dataSource: dataSource
});
</script>
If this option is set and the server response contains that field, then the
errorevent will be fired. Theerrorsfield of the event argument will contain the errors returned by the server.
Specify the error field as a string
<script>
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://run.mocky.io/v3/ef00571f-cd9c-4bb3-a8fc-c98afa9e8de4",
}
},
schema: {
data: "items",
errors: function(response) {
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log("errors as function", response.errors[0])
return response.errors;
}
},
error: function(e) {
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log("error event handler", e.errorThrown);
}
});
dataSource.fetch();
</script>
Specify the error field as a function
<script>
var dataSource = new kendo.data.DataSource({
transport: {
read: {
url: "https://demos.telerik.com/service/v2/core/products",
}
},
schema: {
errors: function(response) {
return response.error;
}
},
error: function(e) {
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(e.errors);
}
});
dataSource.fetch();
</script>
Default: "errors"
schema.groups
Function|StringThe field from the server response which contains the groups. Can be set to a function which is called to return the groups from the response.
The
groupsoption is used only when theserverGroupingoption is set totrue.
The result should have the following format:
[{
aggregates: {
FIEL1DNAME: {
FUNCTON1NAME: FUNCTION1VALUE,
FUNCTON2NAME: FUNCTION2VALUE
},
FIELD2NAME: {
FUNCTON1NAME: FUNCTION1VALUE
}
},
field: FIELDNAME, // the field by which the data items are grouped
hasSubgroups: true, // true if there are subgroups
items: [
// either the subgroups or the data items
{
aggregates: {
//nested group aggregates
},
field: NESTEDGROUPFIELDNAME,
hasSubgroups: false,
items: [
// data records
],
value: NESTEDGROUPVALUE
},
//nestedgroup2, nestedgroup3, etc.
],
value: VALUE // the group key
} /* other groups */
]
schema.model
Object|kendo.data.ModelThe data item (model) configuration.
If set to an object, the Model.define method will be used to initialize the data source model.
If set to an existing kendo.data.Model instance, the data source will use that instance and will not initialize a new one.
schema.parse
FunctionExecuted before the server response is used. Use it to preprocess or parse the server response.
The initially parsed server response that may need additional modifications.
—The data items from the response.
schema.total
Function|StringThe field from the server response which contains the total number of data items. Can be set to a function which is called to return the total number of data items for the response.
- The
schema.totalsetting may be omitted when the Grid is bound to a plainArray(that is, the data items' collection is not a value of a field in the server response). In this case, thelengthof the responseArraywill be used.- The
schema.totalmust be set if theserverPagingoption is set totrueor theschema.dataoption is used.
—The total number of data items.
schema.type
StringThe type of the response.
The supported values are:
"xml""json"
By default, the schema interprets the server response as JSON.
Default: "json"