Event

Three events to which you can attach, change, get and set. the syntax is to use model.bind()

currentService.bind('change', function(e){
    alert(e.field + " just changed its value to " +
    currentService.get([e.field]));
});
  • change, when data is changed or read from the transport
  • error, fired any time an error occurs during data read or data sync
  • requestStart, fired when a data request is about to start.
// set event handler as part of DataSource definition
var dataSource = new kendo.data.DataSource({
  change: function(e){
   // handle event
   }
});
// or set event handler later through the bind method
dataSource.bind("error", function(e){
 // handle event
});

change

/*
Fired when the data source is populated from a JavaScript array 
or a remote service, a data item is inserted, updated or removed, 
the data items are paged, sorted, filtered, or grouped.
*/

// change is used for change the data after the data is retrieved. 

var dataSource = new kendo.data.DataSource({
  transport: {
    read: {
      url: "http://demos.telerik.com/kendo-ui/service/products",
      dataType: "jsonp" //"jsonp" is required for cross-domain requests; use "json" for same-domain requests
    }
  },
  change: function( e ) {
    var data = this.data();
    console.log(data.length); // displays "77"
  }
});

dataSource.fetch();

/*
- The event handler function context (available via the 
this keyword) will be set to the data source instance.

- e.sender
  The data source instance which fired the event.

- e.items
  The array of data items that were affected (or read).
*/

results matching ""

    No results matching ""