My model looks like follows:
My dataSource uses this model and implements transport methods as functions because I need header and other optios on $.ajax calls. I only represent the create function below:
My ajax call returns an updated object with an id created on the server, a created date, an updated date and more.
My issue is the object added to the datasource with a null id and sent to the server for creation is not updated with the data I receive in response from the server.
After some digging into the kendo source code, it seems that an update is attempted by searching the object with the same id, but in my scenario teh id changes because it is created on the server. In this case, the object is not updated.
Can you please validate the following workaround or suggest any better ways:
var Sample = kendo.data.Model.define({ id: 'id', fields: { id: { type: 'string', nullable: true, editable: false }, .... }});My dataSource uses this model and implements transport methods as functions because I need header and other optios on $.ajax calls. I only represent the create function below:
...transport: { create: function(options) { $.ajax(...).done(options.success).fail(options.error); }},...My ajax call returns an updated object with an id created on the server, a created date, an updated date and more.
My issue is the object added to the datasource with a null id and sent to the server for creation is not updated with the data I receive in response from the server.
After some digging into the kendo source code, it seems that an update is attempted by searching the object with the same id, but in my scenario teh id changes because it is created on the server. In this case, the object is not updated.
Can you please validate the following workaround or suggest any better ways:
...transport: { create: function(options) { var that = this; $.ajax(...) .done(function(response) { that.get(null).accept(response); //<--------------------- this actually updates the item with id === null options.success(response); ) .fail(options.error); }},...