简体   繁体   English

Extjs4,如何在编辑功能中恢复编辑的网格单元格值?

[英]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. 我需要在编辑功能中恢复(设置值到编辑前的值)编辑的网格单元格值,而不是在validateedit函数中。

"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. 另请注意, edit事件的第二个参数(您命名为“edit”的参数)不包含cancel属性,即beforeedit事件的属性。 So this line edit.cancel = true won't do anything for you. 所以这行edit.cancel = true不会为你做任何事情。

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. 我也很好奇为什么你没有使用beforeedit事件,它似乎更适合这种事情 - 它为什么它有cancel属性。

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. 如果绑定到网格上的afteredit事件,则可以执行以下操作,具体取决于您要重置的粒度。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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