问题描述
商店加载后如何制作fireEvent
itemclick
.
How do you make a fireEvent
itemclick
after the store loads.
我有这个,但是不起作用:
I have this but it doesn't work:
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
});
这是我在网格视图中的itemclick
事件:
Here is my itemclick
event in grid view:
viewConfig: {
listeners: {
itemclick: function(dv, record, item, index, e) {
alert(record.data.code);
}
}
}
基本上,当网格加载时,它应该触发所选第一行的警报窗口网格.
Basically when the grid loads, it should fire the alert window of the selected first rowof the grid.
推荐答案
itemclick
是View
的事件,而不是Grid
的事件.尝试使用:
itemclick
is event of View
but not of Grid
. Try to use:
grid.getview().fireEvent('itemclick', grid, 0);
顺便说一句,为什么不使用 selectionchange
代替.
And by the way why not use selectionchange
instead.
更新
如果同时具有itemcontextmenu
和selectionchange
处理程序,可能会有些混乱.在这种情况下,我建议回到第一方并使用itemclick
事件.
If you have both itemcontextmenu
and selectionchange
handlers it can be a little bit confusing. In this case I recommend back to square one and use itemclick
event.
但是您的代码需要进行一些修改:
But your code need to have some modifications:
- 将
itemclick
事件分配给网格,而不是将其分配给视图. - 触发
itemclick
时通过实际记录,而不是索引
- Assign
itemclick
event to grid, NOT to it's view. - When firing
itemclick
pass actual record, NOT an index
像这样:
grid.getSelectionModel().select(0);
grid.fireEvent('itemclick', grid, grid.getSelectionModel().getLastSelected());
这是小提琴,以演示我在说什么.
And here is fiddle to demonstrate what I'm talking about.
这篇关于extjs 4网格fireevent itemclick的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!