开发者

Remove context menu / right click in a Ext JS grid

开发者 https://www.devze.com 2023-03-08 04:38 出处:网络
I have a table grid in Ext Js with a selection.CheckboxModel I can multi select items in the grid, but it seems like also right click can select items

I have a table grid in Ext Js with a selection.CheckboxModel I can multi select items in the grid, but it seems like also right click can select items

The question is is there 开发者_Python百科any way to remove right click so it does not select item/s?

Thanks in advance, Bob


To prevent selection with rigth button you can use this code (with Ext JS 4)...

var allowSelection=true;

...

grid.on('beforeitemmousedown', function(grid, record, item, index, event, eOpts) { 
    if (event.button==0) allowStreetSelection=true; else allowSelection=false; 
});

grid.on('beforeselect', function(grid, record, index, eOpts) { 
    return allowSelection; 
});


To stop the context menu, you can catch the rowcontextmenu event and stop it.

grid.on('rowcontextmenu', function(grid,index,e) { e.stopEvent() });

This may also solve your row selection issue but right-click doesn't select rows for me. What version of ExtJS are you using and on which browsers do you see this problem? On ExtJS 3.3 and Firefox 4 and IE 8-9 I can't reproduce it.

Edit: For Ext 4, containercontextmenu looks to be the event to catch. Returning false from that handler should stop the context menu from appearing. I don't have much experience with Ext 4, so let me know if it works for you.


This worked like a charm for me (EXTJS 4.1.2):

grid.on('beforeitemmousedown', function(grid, record, item, index, event, eOpts) {
  return (event.button == 0);
});


We've also met the same problem while using ExtJS4, our solution for now is to modify the original code in extJS.

Find:

} else if (me.isSelected(record) && !e.shiftKey 
        && !e.ctrlKey && me.selected.getCount() > 1) 
{
    me.doSelect(record, keepExisting, false);

You can find them in ext-all.js or in src/selection/Model.js

And change it to:

} else if (me.isSelected(record) && !e.shiftKey && !e.ctrlKey && me.selected.getCount() > 1) {
    if (e.button != 0)
        keepExisting = true;
    else
        keepExisting = false;
    me.doSelect(record, keepExisting, false);

This code will prevent clear current item selections except u're clicking the item with mouse button 0 (left button).

0

精彩评论

暂无评论...
验证码 换一张
取 消