首页 > 解决方案 > ExtJS:如何在右键单击事件中获取所选网格记录的数据?

问题描述

我有一个grid和一个上下文菜单功能。我在上下文菜单上添加了一个新项目,并尝试检索所选记录的数据以进行操作。

我怎样才能做到这一点?

在添加新项目期间覆盖方法;

getGridMenu: function () {
// This function calls base function for right-click events
        var me = this;

        var ret = [
            {
                text: 'Update Password',
                handler: 'onUpdatePassword'
            }
        ];

        return me.callParent().concat(ret);
    },

这是检索选定记录数据的问题。我需要确认选定的记录id,然后我才能使用 CRUD 流程更新记录数据。

onUpdatePassword: function (button) {
        var me = this;

        Ext.MessageBox.confirm(translations.confirm, translations.confirmChangePassword, me.changePassword, me);
    },

changePassword: function (button) {
        var me = this;

        if (button === "yes") {
            //Successfully getting over here and here I need to declare selected row/record's data to manipulate it.
            return new Ext.window.Window({
            autoShow: true,
            title: 'Create Password',
            modal: true,
            width: 250,
            height: 160,
            items: [
                {
                    xtype: 'container',
                    height: 10
                },
                {
                    xtype: 'passwordfld',
                    width: 230,
                    inputType: 'password'
                }
            ],
            dockedItems: [
                {
                    xtype: 'toolbar',
                    dock: 'bottom',
                    items: [
                        {
                            xtype: 'tbfill'
                        },
                        {
                            xtype: 'cancelbutton'
                        },
                        {
                            xtype: 'savebutton'
                        }
                    ]
                }
            ]
        });
        } else {
            me.destroy();
        }
    },

标签: extjsgridrecordright-click

解决方案


将项目的定义更改为:

{
    text: 'Update Password',
    listeners: {
        click: this.onUpdatePassword,
        scope: this
    }
}

现在thisinonUpdatePassword指的是网格

您可以通过以下方式访问选定的行this.getSelectionModel().getSelection()


推荐阅读