add
Appends a data item to the data source.
Parameters
model Object|kendo.data.Model
Either a kendo.data.Model instance or JavaScript object containing the data item field values.
Returns
kendo.data.Model
—The data item which is inserted.
Example - add a data item to a local data source
<script>
var dataSource= new kendo.data.DataSource({
data: [
{ name: "Jane Doe", age: 30 }
]
});
dataSource.add({ name: "John Doe", age: 33 });
var data = dataSource.data();
var lastItem = data[data.length - 1];
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(lastItem.name); // displays "John Doe"
/* The result can be observed in the DevTools(F12) console of the browser. */
console.log(lastItem.age); // displays "33"
</script>
Example - add a data item to a remote data source
<script>
var dataSource = new kendo.data.DataSource({
transport: {
// make JSONP request to https://demos.telerik.com/kendo-ui/service/products/create
create: {
url: "https://demos.telerik.com/kendo-ui/service/products/create",
dataType: "jsonp" // "jsonp" is required for cross-domain requests; use "json" for same-domain requests
},
parameterMap: function(data, type) {
if (type == "create") {
// send the created data items as the "models" service parameter encoded in JSON
return { models: kendo.stringify(data.models) };
}
}
},
batch: true,
schema: {
model: { id: "ProductID" }
}
});
// add a new data item
dataSource.add( { ProductName: "New Product" });
// save the created data item
dataSource.sync();
</script>