以编程方式选择网格行不会触发 ExtJS4 中的 itemclick 事件
Programmatically selecting grid row does not fire itemclick event in ExtJS4
我正在构建一个 ExtJS4 Web 应用程序,我有一个 "page",其中有一个网格,其记录来自数据库。加载网格的商店后,我想选择第一个项目。
这是我目前尝试过的方法:
store.load({
callback: function() {
if(store.count() > 0){
grid.getSelectionModel().select(0);
//grid.getView().select(0);
}
}
});
商店正确加载数据库记录,因为它们显示在我的网格中。第一行也突出显示,就像它被单击一样。但是,我的 itemclick
事件的 listener/controller 没有触发,这与我手动单击该行时不同。
我也试过 grid.getView().select(0);
和 grid.getSelectionModel().selectFirstRow();
但显然,这两个都不是函数。
我的网格行似乎被 itemclick
函数选中,根本没有被调用。
您应该在 'Ext.selection.Model' 中使用 'selectionchange' 侦听器,而不是在网格 class 中使用 'itemclick'。当在网格中单击行和以编程方式选择行时,在这两种情况下都会触发此侦听器。
大概代码是这样的:
Ext.create('Ext.grid.Panel', {
selModel: Ext.create('Ext.selection.Model', {
...
listeners: {
selectionchange: function( this, selected, eOpts ) {
// Write your listener here or fire another event in view controller
}
}
}
store: ...
});
我正在构建一个 ExtJS4 Web 应用程序,我有一个 "page",其中有一个网格,其记录来自数据库。加载网格的商店后,我想选择第一个项目。
这是我目前尝试过的方法:
store.load({
callback: function() {
if(store.count() > 0){
grid.getSelectionModel().select(0);
//grid.getView().select(0);
}
}
});
商店正确加载数据库记录,因为它们显示在我的网格中。第一行也突出显示,就像它被单击一样。但是,我的 itemclick
事件的 listener/controller 没有触发,这与我手动单击该行时不同。
我也试过 grid.getView().select(0);
和 grid.getSelectionModel().selectFirstRow();
但显然,这两个都不是函数。
我的网格行似乎被 itemclick
函数选中,根本没有被调用。
您应该在 'Ext.selection.Model' 中使用 'selectionchange' 侦听器,而不是在网格 class 中使用 'itemclick'。当在网格中单击行和以编程方式选择行时,在这两种情况下都会触发此侦听器。
大概代码是这样的:
Ext.create('Ext.grid.Panel', {
selModel: Ext.create('Ext.selection.Model', {
...
listeners: {
selectionchange: function( this, selected, eOpts ) {
// Write your listener here or fire another event in view controller
}
}
}
store: ...
});