简体   繁体   English

更改其值时更新RowEditing字段

[英]Update RowEditing Fields when change its value

I am using Extjs 4.2, so i have a grid with rowediting plugin. 我正在使用Extjs 4.2,所以我有一个带有rowediting插件的网格。 All works fine, I want to know how I can update one field value, depending on another field. 一切正常,我想知道如何根据一个字段更新一个字段的值。 I mean for example if in my grid I have field1, and field2, I need to update field3 value with field1 + field2 values when one of those were changed. 我的意思是,例如,如果在我的网格中我有field1和field2,则当其中之一更改时,我需要用field1 + field2值更新field3值。 Normally using jquery we can code a change event for each of the fields, but how i can do this on rowediting event? 通常使用jquery我们可以为每个字段编写一个change事件,但是我如何在rowediting事件上做到这一点?

Is this possible? 这可能吗?

You can use edit events of rowedit as follow: 您可以按以下方式使用rowedit edit事件:

Sencha Fiddle : Grid RowEditor - Change cell value based on condition Sencha Fiddle: 网格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')));
}

})

When you use RowEditor, the e.field value entirely depends on the field that was clicked on to edit the row. 使用RowEditor时,e.field值完全取决于单击以编辑行的字段。

To illustrate the problem: 为了说明问题:

  1. In the previous answer, open the fiddle link ( https://fiddle.sencha.com/#fiddle/4pj ). 在上一个答案中,打开小提琴链接( https://fiddle.sencha.com/#fiddle/4pj )。
  2. Double click the email field and change the name. 双击电子邮件字段并更改名称。
  3. The handler will not update the result field as e.field will now be 'email' and not 'name'. 处理程序将不会更新结果字段,因为e.field现在将是“电子邮件”而不是“名称”。

That is, Row Editor considers the field on which you click as the edited field. 也就是说,行编辑器将您单击的字段视为已编辑的字段。 This does not make sense as it is a 'row' editor and is most probably used to edit multiple fields in the row. 这是没有意义的,因为它是“行”编辑器,很可能用于编辑行中的多个字段。

To get the list of only modified fields, use e.record.getChanges() . 要获取仅修改字段的列表,请使用e.record.getChanges() These will give you only the modified fields and their new values. 这些将仅为您提供修改后的字段及其新值。

You have to add editors to the columns, the editor is like any component, has listeners, type etc. then add a change listener 您必须将编辑器添加到列中,该编辑器就像任何组件一样,具有侦听器,类型等,然后添加一个更改侦听器

Example: ... 示例:...

{
    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
    },

... ...

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

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