Edit this page

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];
console.log(lastItem.name); // displays "John Doe"
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>
Is this article helpful? Yes / No
Thank you for your feedback!

Give article feedback

Tell us how we can improve this article

close
Dummy