Thursday, 1 January 2015

model Deletion in ExtJS 5

While I was working with ExtJS 5, I faced a problem in deleting a record. 'erase' is a method in ExtJS 5 to delete a model, which is a counter part of 'destroy' method in ExtJS 4. I tried 'erase' method on model to delete it using rest and it was not sending any DELETE request to the server. Here is the sample code snippet
var user = Ext.create('User', {
   extend : '',
   fields : ['id', 'name', 'email'],

   proxy : {
    type : 'rest',
    url : '/users'

user.set('id', '12345');

In the preceding function call, will not be any XHR request with 'DELETE' method as we expect, if you are using ExtJS-5.1.0. In ExtJS 4, if there is any change in the ID property, it calls a function(changeId) that does house keeping of a model hence, model's phantom becomes false whereas in ExtJS5, user.set('id','12345') will not change user's phantom to false(When we create model using Ext.create, default phantom value will be true). Since it is a phantom record(new record), it will not call any 'DELETE' request.

Here is a simple hack to handle this problem. We hope there will be a fix in their future releases.

user.commit(); // user.phantom becomes false
user.phantom = false; //Make phantom as false manually

No comments:

Post a Comment