簡體   English   中英

Extjs4,如何在編輯功能中恢復編輯的網格單元格值?

[英]Extjs4, how to restore edited grid cell value in edit 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
        }
        });
    }
}

如何更改網格單元格值(編輯器)?

謝謝!

拒絕方法怎么樣:

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

另請注意, edit事件的第二個參數(您命名為“edit”的參數)不包含cancel屬性,即beforeedit事件的屬性。 所以這行edit.cancel = true不會為你做任何事情。

我也很好奇為什么你沒有使用beforeedit事件,它似乎更適合這種事情 - 它為什么它有cancel屬性。

如果綁定到網格上的afteredit事件,則可以執行以下操作,具體取決於您要重置的粒度。

注意 :我沒有添加任何邏輯來保持快速和直截了當。

僅重置當前更改/單元格

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

重置整個記錄/行

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

重置整個網格

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM