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

问题描述 投票:3回答:2

我需要在编辑功能中恢复(设置值到编辑前的值)编辑的网格单元格值,而不是在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
        }
        });
    }
}

如何更改网格单元格值(编辑器)?

谢谢!

extjs extjs4
2个回答
4
投票

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

另请注意,edit事件的第二个参数(您命名为“edit”的参数)不包含cancel属性,即beforeedit事件的属性。所以这行edit.cancel = true不会为你做任何事情。

我也很好奇为什么你没有使用beforeedit事件,它似乎更适合这种事情 - 它为什么它确实有cancel属性。


0
投票

如果绑定到网格上的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();
}
© www.soinside.com 2019 - 2024. All rights reserved.