简体   繁体   中英

Extjs4, how to restore edited grid cell value in edit function?

I need to restore(set value to before edited value) edited grid cell value in edit function, not in validateedit function.

"orderList": {
    validateedit: function (plugin, edit) {
      //validate...
    },
    edit: function (plugin, edit) {
        Ext.MessageBox.confirm('Confirm', 'Are you sure to change this order status?', function (btn) {
        if (btn == 'yes') {
            //update
        } else {
            // I want to rollback!
            edit.cancel = true;
            edit.record.data[edit.field] = edit.originalValue; //it does not work
        }
        });
    }
}

How to change the grid cell value (editor)?

Thanks!

How about the reject method :

"orderList": {
    validateedit: function (plugin, edit) {
      //validate...
    },
    edit: function (plugin, edit) {
        Ext.MessageBox.confirm('Confirm', 'Are you sure to change this order status?', function (btn) {
            if (btn == 'yes') {
                //update
            } else {
                edit.record.reject(); // this should revert all changes
            }
        });
    }
}

Also note that the second argument (the one you named "edit") of the edit event does not contain a cancel property, that is a property of the beforeedit event. So this line edit.cancel = true won't do anything for you.

I was also curious why you aren't using the beforeedit event, it seems more ideally suited for this kind of thing - that it why it does have that cancel property.

If you bind to the afteredit event on the grid can do something like the following, depending on the granularity you would like to reset.

Note : I didn't add any logic to keep things quick and straight to the point.

Reset Only the Current Change/Cell

grid.on('afteredit', function(e) {
  e.record.set(e.field, e.originalValue);
}

Reset the Whole Record/Row

grid.on('afteredit', function(e) {
  e.record.reject();
}

Reset the Whole Grid

grid.on('afteredit', function(e) {
  e.grid.store.rejectChanges();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM