2012-09-03 42 views
2

我需要開發一個網格包裝到一個可浮動窗口中:當窗口顯示時,我需要關注某一行,然後用導航鍵向上或向下移動。 現在,我明白如何使用grid.getView()。focusRow(index))來關注指定的行,但是,這樣做,我無法在網格中向上或向下移動,就好像網格已經丟失了焦點。ExtJS 4柵格重點加導航

下面的代碼:

var storage = Ext.create ('Ext.data.Store', { 
    fields: ['id', 'name'] , 
    data: [ 
     {id:0,name:'foo'} , 
     {id:1,name:'boo'} , 
     {id:2,name:'koo'} , 
     {id:3,name:'zoo'} , 
     {id:4,name:'moo'} , 
     {id:5,name:'too'} , 
     {id:6,name:'goo'} , 
     {id:7,name:'poo'} , 
     {id:8,name:'loo'} , 
     {id:9,name:'roo'} , 
     {id:10,name:'hoo'} 
    ] 
}); 

Ext.create ('Ext.grid.Panel', { 
    title: 'My Grid' , 
    width: 300 , 
    height: 200 , 
    store: storage , 
    renderTo: Ext.getBody() , 

    columns: [{ 
     header: 'ID' , 
     dataIndex: 'id' 
    } , { 
     header: 'Name' , 
     dataIndex: 'name' , 
     flex: 1 
    }] , 

    listeners: { 
     afterlayout: function (grid) { 
      var view = grid.getView(); 

      view.focusRow (storage.getCount() - 1); 
      view.highlightItem (view.getNode (storage.getCount() - 1)); 
     } 
    } 
}); 

所以,在這之後,我怎麼能「專注」電網得到它通航?

回答

5

您需要選擇這樣的行爲它是鍵盤通航:

grid.getView().focus(); 
grid.getSelectionModel().select(0); // or whatever the row index is 

而且做一個viewready事件偵聽器。這就是viewready事件的用途。

很明顯,網格至少需要一條記錄才能正常工作,您應該首先檢查該條件。

+0

非常感謝!它很好用;) – Wilk

0

可以使用focusRow()功能這個問題

grid.getView().focusRow(0);