extjs6-网格上下文菜单,通过行选择

时间:2018-11-13 20:27:27

标签: extjs contextmenu

在我的extjs6项目中,我有一个网格,我想添加一些功能来右键单击网格,从菜单栏中选择项目并启动弹出窗口,但将行选择传递给click方法。

到目前为止,我可以使用右键单击菜单栏,但是单击菜单项时,我希望通过网格中的选定行。有人可以帮助我将网格行选择传递给控制器​​方法吗?

我的观点

Ext.define('Example.ContextMenu', {
xtype: 'contextMenuMarketDrilldownAccount',
extend: 'Ext.menu.Menu',
items: [{
    text: 'Market Drilldown by Account',
    listeners: {
        click: 'onDownloadTopdayRecapContextButton2'
    }
}]
});

             //removing a lot of code to make it readable here
            xtype: 'grid',
            title: 'Details',
            itemId: 'detailsGridID',
            bind: {
                store: '{myDetailsStore}'
            },
            flex: 3,
            margin: '5px 0px 0px 0px',
            ui: 'featuredpanel-framed',
            cls: 'custom-grid',
            height: '100%',
            collapsible: true,
            collapseDirection: 'left',
            listeners: {
                itemcontextmenu: 'showContextMenu2'
            },

控制器

    showContextMenu2: function (view, rec, node, index, e) {
    e.stopEvent();
    debugger;
    //var selectedMarket = rec.get('BBSymbol');
    this.getContextMenu2().show().setPagePosition(e.getXY());
    return false;
},

getContextMenu2: function () {
    if (!this.contextMenu) {
        this.contextMenu = this.getView().add({ xtype: 'contextMenuMarketDrilldownAccount' });
    }
    return this.contextMenu;
},

1 个答案:

答案 0 :(得分:2)

要解决此问题,请将块 this.getContextMenu2()更改为 this.getContextMenu2(rec)

showContextMenu2: function (view, rec, node, index, e) {
    e.stopEvent();
    debugger;
    //var selectedMarket = rec.get('BBSymbol');
    this.getContextMenu2(rec).show().setPagePosition(e.getXY());
    return false;
},

getContextMenu2: function (rec) {
    if (!this.contextMenu) {
        this.contextMenu = this.getView().add({ 
            xtype: 'contextMenuMarketDrilldownAccount',
            currentRecord: rec 
        });
    }
    return this.contextMenu;
}

//Then you catch a currentRecord on a contextMenuMarketDrilldownAccount component.