Extjs4 extjs 4网格fireevent项单击

Extjs4 extjs 4网格fireevent项单击,extjs4,Extjs4,如何制作fireEventItem在商店加载后单击 我有这个,但不起作用: pcfstore.on('load', function(){ //auto select first row; Ext.getCmp('pcf_grid').getSelectionModel().select(0); // this works //fire itemclick event var grid= Ext.getCmp('pcf_grid'); grid.fireEvent('

如何制作
fireEvent
Item在商店加载后单击

我有这个,但不起作用:

pcfstore.on('load', function(){
   //auto select first row;
   Ext.getCmp('pcf_grid').getSelectionModel().select(0); // this works

   //fire itemclick event
  var grid= Ext.getCmp('pcf_grid');
  grid.fireEvent('itemclick', grid, 0); //this doesnt work

}); 
这是我的
项目在网格视图中单击
事件:

viewConfig: {
    listeners: {
    itemclick: function(dv, record, item, index, e) {
           alert(record.data.code);
       }
    }
}
基本上,当网格加载时,它应该触发所选第一行的警报窗口
网格的事件。

项单击
视图的事件
,但不是
网格的事件
。尝试使用:

grid.getview().fireEvent('itemclick', grid, 0);
顺便问一下,为什么不改用它呢

更新

如果同时具有
itemcontextmenu
selectionchange
处理程序,可能会有点混乱。在这种情况下,我建议回到原点,使用
itemclick
event

但您的代码需要进行一些修改:

  • itemclick
    事件分配给网格,而不是它的视图
  • 触发
    item时,单击
    传递实际记录,而不是索引
  • 像这样:

    grid.getSelectionModel().select(0);
    grid.fireEvent('itemclick', grid, grid.getSelectionModel().getLastSelected());
    

    这里是为了演示我所说的。

    经过几个小时的搜索,我找到了一个解决方案。ExtJs4似乎存在一个问题,使以下函数无法为我工作:

    grid.getSelectionModel().select(0);
    

    在我的控制器中,我使用以下代码:

    store.load({
        callback: function (records, operation, success) {        
            var rowIndex = this.find('id', myRecord);  //where 'id': the id field of your model. You can replace 'id' with your unique field.. And 'this' is your store.
            grid.getView().select(rowIndex);
        }
    })
    
    其中myRecord是要突出显示和选择的记录。
    然后它就像一个符咒。我突出显示并选择了第0行。但是,当使用此代码选择行时,没有触发itemclick侦听器。

    thanx以获得快速响应。然而,我一直在使用这个网格操作示例,它在右键单击时显示上下文菜单。我更改了fireEvent项目单击以选择按您的建议更改。我想做的是——如果我左键单击鼠标,它将显示警告消息,右键单击将显示关联菜单。它现在所做的是,如果我右键单击网格中的某个项目,它仍然会显示警报消息框。知道有什么解决办法可以解决这个问题吗?再次触发tnx.selectionchange事件,而不是itemcontextmenu事件——这就是为什么即使我右键单击鼠标,它仍会显示警报框。再次感谢Thanx的帮助。非常感谢。很抱歉,我在extjs4.2上尝试了此操作,得到错误
    无法读取未定义的
    的属性'shiftKey',它指向
    grid.getview().firevent('itemclick',grid,0)代码行。。
    
    store.load({
        callback: function (records, operation, success) {        
            var rowIndex = this.find('id', myRecord);  //where 'id': the id field of your model. You can replace 'id' with your unique field.. And 'this' is your store.
            grid.getView().select(rowIndex);
        }
    })