在按钮上单击选择网格行数据

时间:2012-11-12 13:42:51

标签: extjs4

我有一个关于从选定网格行获取数据的问题。

这是存储数据库信息的网格面板:

gridHoldingPanel = _ui.createGrid({
                extClass: 'Ext.grid.Panel',
                width: windowSettings.gridPanel.width,
                height: windowSettings.gridPanel.height,
                id: _id.archiveHistoryGrid,
                title: null,
                selModel: 'rowmodel',
                store: ds,
                columns: [{
                    header: 'Archived at',
                    dataIndex: 'archived_at',
                    width: 120
                }, {
                    header: 'Calls Starting',
                    dataIndex: 'date_from',
                    width: 120
                }, {
                    header: 'Calls Ending',
                    dataIndex: 'date_to',
                    width: 120
                }, {
                    header: 'Calls Archived',
                    dataIndex: 'total_calls',
                    width: 90
                }, {
                    header: 'Database',
                    dataIndex: 'db_archived',
                    width: 70
                }, {
                    header: 'Archive Path',
                    dataIndex: 'path',
                    width: 200
                }],
                stripeRows: true,
                listeners : {
                    itemdblclick: function(dv, record, item, index, e) {
                        var win = _restoreCallsWindow(), field= win.down('textfield');
                        field.setValue(record.get('path'));
                        win.show();
                    }
                }
            })

这是带有按钮的面板,它与网格位于同一窗口中:

buttonsPanel = _ui.createPanel({
                border: false,
                width: windowSettings.buttonsPanel.width,
                height: windowSettings.buttonsPanel.height,
                id: _id.archiveHistoryButtons,
                items: [{
                    layout: 'hbox',
                    border: false,
                    margin: '5px 5px 5px 5px',
                    items: [
                    //Refresh button
                    _ui.createButton({
                        text: 'text_auto_refresh',
                        cls: 'sense-archive-button-buttons',
                        id: _id.arHistoryRefresh,
                        handler: function() {
                            ds.load();
                        }
                    }),
                    //Restore button
                    _ui.createButton({
                        text: 'text_restore',
                        margin: '0px 0px 0px 5px',
                        cls: 'sense-archive-button-buttons',
                        id: _id.arHistoryRestore,
                        handler: function(grid, rowIndex, colIndex) {
                            var row = gridHoldingPanel.getSelectionModel().getSelection();
                            console.log(row);
                        }
                    }),
                    //Close window button
                    _ui.createButton({
                        text: 'text_close',
                        margin: '0px 0px 0px 5px',
                        cls: 'sense-archive-button-buttons',
                        id: _id.arHistoryClose,
                        handler: function ( ) {
                            _historyWindow().close();
                        }
                    })]
                }]
            })

我要做的是点击恢复按钮时会打开另一个包含文本输入字段的窗口,打开时我想显示数据网格中所选行的路径值。

正如您所看到的那样,我在恢复按钮中的代码将行值返回给整个对象,当我尝试从对象record.data获取数据时,返回给我undefined

有人可以帮我这个吗?

1 个答案:

答案 0 :(得分:1)

问题在于您将按钮处理程序参数与项目单击事件功能混合在一起。因此对于处理程序,您只能使用params按钮。 getSelection函数返回一个选择数组,因此如果你有一个select,那么该行将实际上是第一个元素。简单的修复将是:

handler: function(btn) {
                            var records = gridHoldingPanel.getSelectionModel().getSelection();
                            console.log('the selected record path' +records[0].data.path);
                        }
相关问题