offlineData
Gets or sets the offline state of the data source.
Parameters
data Array
The array of data items that replace the current offline state of the data source.
Returns
Array
—An array of JavaScript objects that represent the data items. Changed data items have a __state__
field attached. That field indicates the type of change: "create"
, "update"
, or "destroy"
. Unmodified data items do not have a __state__
field.
Example - get the offline state
<script>
var dataSource = new kendo.data.DataSource({
offlineStorage: "products-offline",
transport: {
read: {
url: "https://demos.telerik.com/kendo-ui/service/products",
dataType: "jsonp"
},
update: {
url: "https://demos.telerik.com/kendo-ui/service/products/update",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
schema: {
model: {
id: "ProductID"
}
}
});
dataSource.fetch(function() {
// go in offline mode
dataSource.online(false);
// change the ProductName field of the first data item
dataSource.at(0).set("ProductName", "Updated");
// sync to accept the changes
dataSource.sync();
// get the offline data
var offlineData = dataSource.offlineData();
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(offlineData[0].__state__); // displays "update"
});
</script>