2012-11-12 46 views
0

我有一個關於從選定網格行獲取數據的問題。點擊按鈕,選取所選網格行數據

這是該數據庫信息存儲在網格面板:

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

問題是你混合了按鈕處理程序參數與項目單擊事件功能。所以對於處理程序,您將只有按鈕的參數。 getSelection函數返回一個選擇數組,所以如果你有一個select,那麼這個行實際上就是第一個元素。簡單的修復將是:

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

我想我做了,我是新的ExtJs。非常感謝您的解決方案。 – user1812671

相關問題