我有一個帶有上下文菜單的網格。我知道如何通過右鍵點擊來防止行選擇。我只是這樣做:如何防止右鍵點擊取消行取消
var allowSelection=true;
Ext.getCmp('grid').on('beforeitemmousedown', function(grid, record, item, index, event, eOpts) {
if (event.button==0) allowSelection=true ;
else allowSelection=false;
});
Ext.getCmp('grid').on('beforeselect', function(grid, record, index, eOpts) {
return allowSelection;
});
但我現在需要的是防止行取消選擇。事實上,即使當前代碼阻止行選擇,它也不會阻止行取消選擇。
編輯
我右擊事件導致一個上下文菜單彈出。代碼的一部分,這是它
listeners:{
itemcontextmenu:function(view,record,item,index,e){
e.stopEvent();
gridMenu.showAt(e.getXY());
},
containercontextmenu:function(view, e){
e.stopEvent();
gridMenu.showAt(e.getXY());
}
...
此代碼嵌套在網格的viewconfig內。所以,我只是不想觸發行取消選擇,當我的上下文菜單彈出。
編輯
嗯,我做到了我自己。一個剛剛添加return false
:
if (event.button==0) allowSelection=true ;
else {
allowSelection=false;
return false;
}
你應該給自己的答案作爲真正的答案,而不是編輯。 –
您提供的答案正在工作,並且對按鈕 –