add
(model)
: Object
var model = kendo.data.Model.extend({
id: "orderId",
fields: {
name: "customerName",
description: "orderDescription",
address: "customerAddress"
}
});
// add a new model item to the data source. If a model has not been declared as above, a new
// model instance will be created for you.
dataSource.add({ name: "John Smith", description: "Product Description", address: "123 1st Street" });
model
: Object
aggregate
(val)
: Array
dataSource.aggregate({ field: "orderId", aggregate: "sum" });
val
: Object|Array
(optional)
aggregates
()
: Array
var aggr = dataSource.aggregates();
at
(index)
: Object
// returns the 4th item in the collection
var order = dataSource.at(3);
index
: Number
cancelChanges
(model)
// we have updated 2 items and deleted 1. All of those changes will be discarded.
dataSource.cancelChanges();
model
data
(value)
: Array
var data = dataSource.data();
value
fetch
(callback)
dataSource.fetch();
callback
filter
(val)
: Array
Supported filter operators/aliases are:
dataSource.filter({ field: "orderId", operator: "eq", value: 10428 });
dataSource.filter([
{ field: "orderId", operator: "neq", value: 42 },
{ field: "unitPrice", operator: "ge", value: 3.14 }
]);
val
: Object|Array
(optional)
get
(id)
: Object
var order = dataSource.get(1); // retrieves the "order" model item with an id of 1
id
: Number
getByUid
(uid)
: Object
uid
: String
group
(val)
: Array
dataSource.group({ field: "orderId" });
val
: Object|Array
(optional)
insert
(index, model)
: Object
var model = kendo.data.Model.extend({
id: "orderId",
fields: {
name: "customerName",
description: "orderDescription",
address: "customerAddress"
}
});
// insert a new model item at the very front of the collection
dataSource.insert(0, { name: "John Smith", description: "Product Description", address: "123 1st Street" });
index
: Number
model
: Object
page
(val)
: Number
dataSource.page(2);
val
: Number
(optional)
pageSize
(val)
: Number
dataSource.pageSize(25);
val
: Number
(optional)
query
(options)
// create a view containing at most 20 records, taken from the
// 5th page and sorted ascending by orderId field.
dataSource.query({ page: 5, pageSize: 20, sort: { field: "orderId", dir: "asc" } });
// moves the view to the first page returning at most 20 records
// but without particular ordering.
dataSource.query({ page: 1, pageSize: 20 });
options
: Object
(optional)
read
(data)
var dataSource = new kendo.data.DataSource({
transport: {
read: "orders.json";
}
});
// the datasource will not contain any data until a read is called
dataSource.read();
data
remove
(model)
// get the model item with an id of 1 from the DataSource
var itemToRemove = dataSource.get(1);
// remove the item from the DataSource
dataSource.remove(itemToRemove);
model
: Object
sort
(val)
: Array
dataSource.sort({ field: "orderId", dir: "desc" });
dataSource.sort([
{ field: "orderId", dir: "desc" },
{ field: "unitPrice", dir: "asc" }
]);
val
: Object | Array
(optional)
sync
()
If the DataSource is in batch mode, only one call will be made for each type of operation. Otherwise, the DataSource will send one command per pending item change per change type.
// we have deleted 2 items and updated 1. If not in batch mode, this will send three commands to the server
dataSource.sync();
total
()
var total = dataSource.total();
totalPages
()
: Number
var pages = dataSource.totalPages();
view
()
: Array
var dataSource = new kendo.data.DataSource({
transport: {
read: "orders.json"
}
change: function(e) {
// create a template instance
var template = kendo.template($("#template").html());
// render a view by passing the data to a template
kendo.render(template, dataSource.view());
}
});