Inserts a data item in the data source at the specified index.


index Number

The zero-based index at which the data item will be inserted.

model Object||

Either a instance or a JavaScript object containing the field values.

Returns—The data item which is inserted.

Example - insert a data item

var dataSource = new{
  data: [
    { id: 1, name: "Jane Doe" }
  schema: {
    model: { id: "id" }
dataSource.fetch(function() {
  var dataItem = dataSource.insert(0, { name: "John Doe" });
  var index = dataSource.indexOf(dataItem);
/* The result can be observed in the DevTools(F12) console of the browser. */
  console.log(index); // displays "0"
In this article