sync
Saves any data item changes.
The sync method will request the remote service if:
- The
transport.createoption is set and the data source contains new data items. - The
transport.destroyoption is set and data items have been removed from the data source. - The
transport.updateoption is set and the data source contains updated data items.
Returns
Promise—A promise that will be resolved when all sync requests have finished successfully, or rejected if any single request fails.
Example - save the changes
<script>
var dataSource = new kendo.data.DataSource({
batch: true,
transport: {
read: {
url: "https://demos.telerik.com/service/v2/core/products",
dataType: "json"
},
update: {
url: "https://demos.telerik.com/service/v2/core/products/update",
type: "POST",
contentType: "application/json"
},
destroy: {
url: "https://demos.telerik.com/service/v2/core/products/destroy",
type: "POST",
contentType: "application/json"
}
},
schema: {
model: { id: "ProductID" }
}
});
dataSource.fetch(function() {
var product = dataSource.at(0);
product.set("UnitPrice", 20);
var anotherProduct = dataSource.at(1);
anotherProduct.set("UnitPrice", 20);
var yetAnotherProduct = dataSource.at(2);
dataSource.remove(yetAnotherProduct);
dataSource.sync(); // makes a request to https://demos.telerik.com/service/v2/core/products/update" and https://demos.telerik.com/service/v2/core/products/destroy
});
</script>
In this article