我使用的是 Extjs 4.2,所以我有一个带有行编辑插件的网格。一切正常,我想知道如何根据另一个字段更新一个字段值。我的意思是,例如,如果在我的网格中有 field1 和 field2,当其中一个被更改时,我需要field3
用field1
+值更新值。field2
通常使用 jquery,我们可以为每个字段编写一个更改事件,但我如何在行编辑事件上做到这一点?
这可能吗?
您可以使用以下edit
事件rowedit
:
Sencha Fiddle:Grid RowEditor - 根据条件更改单元格值
grid.on('edit', function(editor, e){
/**
* here I am checking the column name to complete process
* you change what you want
*/
if (e.field == "name") {
e.record.set('result', parseInt(e.record.get('dummy')) + parseInt(e.record.get('age')));
}
})
您必须将编辑器添加到列中,编辑器就像任何组件一样,具有侦听器、类型等,然后添加更改侦听器
例子: ...
{
header: 'HeaderName',
dataIndex: 'man_peso',
type: 'number',
width: 50,
editor: {
enableKeyEvents: true,
listeners: {
change: function(c, e, eOpts) {
//here you can modify others components
}
},
xtype: 'textfield',
maskRe: /[0-9\.]/,
maxLength: 16
},
...
当您使用 RowEditor 时,e.field 值完全取决于单击以编辑行的字段。
为了说明问题:
也就是说,行编辑器将您单击的字段视为已编辑字段。这没有意义,因为它是一个“行”编辑器,很可能用于编辑行中的多个字段。
要获取仅修改字段的列表,请使用e.record.getChanges()
. 这些只会为您提供修改后的字段及其新值。