我需要开发一个包装成可浮动窗口的网格:当窗口显示时,我需要专注于某一行,然后我必须使用导航键向上或向下移动。现在,我了解了如何聚焦指定的行(使用grid.getView().focusRow(index)),但这样做后,我无法在网格中向上或向下移动,就好像网格失去了焦点一样。
这是代码:
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));
}
}
});
那么,在那之后,我如何"集中"网格以使其可导航
您需要选择这样的行才能在键盘上导航:
grid.getView().focus();
grid.getSelectionModel().select(0); // or whatever the row index is
并在viewready
事件侦听器中执行。这就是viewready
事件的作用。
显然,网格至少需要一条记录才能正常工作,您应该首先检查该条件。
您可以使用focusRow()
函数来处理此问题
grid.getView().focusRow(0);