• add (model) : Object
    Adds a new Model instance to the DataSource

    Example

    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" });

    Parameters

    model: Object
    Either a Model instance or raw object from which the Model will be created
    Returns
    Object The Model instance which has been added
  • aggregate (val) : Array
    Get current aggregate descriptors or applies aggregates to the data.

    Example

    dataSource.aggregate({ field: "orderId", aggregate: "sum" });

    Parameters

    val: Object|Array (optional)
    Aggregate(s) to be applied to the data.
    Returns
    Array Current aggregate descriptors
  • aggregates () : Array
    Get result of aggregates calculation

    Example

    var aggr = dataSource.aggregates();
    Returns
    Array Aggregates result
  • at (index) : Object
    Returns the raw data record at the specified index

    Example

    // returns the 4th item in the collection
    var order = dataSource.at(3);

    Parameters

    index: Number
    The zero-based index of the data record
    Returns
    Object
  • cancelChanges (model)
    Cancel the changes made to the DataSource after the last sync. Any changes currently existing in the model will be discarded.

    Example

    // we have updated 2 items and deleted 1. All of those changes will be discarded.
    dataSource.cancelChanges();

    Parameters

    model
  • data (value) : Array
    Get data returned from the transport

    Example

    var data = dataSource.data();

    Parameters

    value
    Returns
    Array Array of items
  • fetch (callback)
    Fetches data using the current filter/sort/group/paging information. If data is not available or remote operations are enabled data is requested through the transport, otherwise operations are executed over the available data.

    Example

    dataSource.fetch();

    Parameters

    callback
  • filter (val) : Array
    Get current filters or filter the data.

    Supported filter operators/aliases are:

    Equal To
    "eq", "==", "isequalto", "equals", "equalto", "equal"
    Not Equal To
    "neq", "!=", "isnotequalto", "notequals", "notequalto", "notequal", "ne"
    Less Then
    "lt", "<", "islessthan", "lessthan", "less"
    Less Then or Equal To
    "lte", "<=", "islessthanorequalto", "lessthanequal", "le"
    Greater Then
    "gt", ">", "isgreaterthan", "greaterthan", "greater"
    Greater Then or Equal To
    "gte", ">=", "isgreaterthanorequalto", "greaterthanequal", "ge"
    Starts With
    "startswith"
    Ends With
    "endswith"
    Contains
    "contains", "substringof"

    Example

    dataSource.filter({ field: "orderId", operator: "eq", value: 10428 });
    dataSource.filter([
         { field: "orderId", operator: "neq", value: 42 },
         { field: "unitPrice", operator: "ge", value: 3.14 }
    ]);

    Parameters

    val: Object|Array (optional)
    Filter(s) to be applied to the data.
    Returns
    Array Current filter descriptors
  • get (id) : Object
    Retrieves a Model instance by given id.

    Example

    var order = dataSource.get(1); // retrieves the "order" model item with an id of 1

    Parameters

    id: Number
    The id of the model to be retrieved
    Returns
    Object Model instance if found
  • getByUid (uid) : Object
    Retrieves a Model instance by its UID.

    Parameters

    uid: String
    The uid of the record to be retrieved
    Returns
    Object Model instance if found
  • group (val) : Array
    Get current group descriptors or group the data.

    Example

    dataSource.group({ field: "orderId" });

    Parameters

    val: Object|Array (optional)
    Group(s) to be applied to the data.
    Returns
    Array Current grouping descriptors
  • insert (index, model) : Object
    Inserts a new Model instance to the DataSource.

    Example

    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" });

    Parameters

    index: Number
    Index at which the Model will be inserted
    model: Object
    Either a Model instance or raw object from which the Model will be created
    Returns
    Object The Model instance which has been inserted
  • page (val) : Number
    Get current page index or request a page with specified index.

    Example

    dataSource.page(2);

    Parameters

    val: Number (optional)
    The index of the page to be retrieved
    Returns
    Number Current page index
  • pageSize (val) : Number
    Get current pageSize or request a page with specified number of records.

    Example

    dataSource.pageSize(25);

    Parameters

    val: Number (optional)
    The of number of records to be retrieved.
    Returns
    Number Current page size
  • query (options)
    Executes a query over the data. Available operations are paging, sorting, filtering, grouping. If data is not available or remote operations are enabled, data is requested through the transport. Otherwise operations are executed over the available data.

    Example

    
    // 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 });

    Parameters

    options: Object (optional)
    Contains the settings for the operations. Note: If setting for previous operation is omitted, this operation is not applied to the resulting view
  • read (data)
    Read the data into the DataSource using the transport read definition

    Example

    var dataSource = new kendo.data.DataSource({
        transport: {
            read: "orders.json";
        }
    });
    // the datasource will not contain any data until a read is called
    dataSource.read();

    Parameters

    data
  • remove (model)
    Remove given Model instance from the DataSource.

    Example

    // 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);

    Parameters

    model: Object
    Model instance to be removed
  • sort (val) : Array
    Get current sort descriptors or sorts the data.

    Example

    dataSource.sort({ field: "orderId", dir: "desc" });
    dataSource.sort([
         { field: "orderId", dir: "desc" },
         { field: "unitPrice", dir: "asc" }
    ]);

    Parameters

    val: Object | Array (optional)
    Sort options to be applied to the data
    Returns
    Array Current sort descriptors
  • sync ()
    Synchronizes changes through the transport. Any pending CRUD operations will be sent to the server.

    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.

    Example

    // we have deleted 2 items and updated 1. If not in batch mode, this will send three commands to the server
    dataSource.sync();
  • total ()
    Get the total number of records

    Example

    var total = dataSource.total();
  • totalPages () : Number
    Get the number of available pages.

    Example

    var pages = dataSource.totalPages();
    Returns
    Number Number of available pages.
  • view () : Array
    Returns a view of the data with operation such as in-memory sorting, paring, grouping and filtering are applied. To ensure that data is available this method should be use from within change event of the dataSource.

    Example

    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());
        }
    });
    Returns
    Array Array of items