PDA

View Full Version : Extjs4.1 treepanel right click selects the node(feature or bug)



klodoma1
17 Jul 2012, 4:43 AM
Hi,

I noticed that in ext4 the right click in a treepanel selects the node and triggers the select event.
In ext3 this was not working like this, so I am not sure if it can considered a feature or a bug.

Is there any way to suppress this functionality -> right clicks should not select the node.

scottmartin
17 Jul 2012, 2:55 PM
I found the following:



var allowSelection = true;

var store = Ext.create('Ext.data.TreeStore', {
root: {
expanded: true,
children: [
{ text: "detention", leaf: true },
{ text: "homework", expanded: true, children: [
{ text: "book report", leaf: true },
{ text: "alegrbra", leaf: true}
] },
{ text: "buy lottery tickets", leaf: true }
]
}
});

var treePanel = Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody()
});

treePanel.on('beforeitemmousedown', function(grid, record, item, index, event, eOpts) {
allowSelection = (event.button == 0) ? true : false;
});

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


Regards,
Scott
‚Äč

klodoma1
17 Jul 2012, 11:29 PM
Yes, I though also on this approach.

A more simple solution would be the following, just return false in the event beforeitemmousedown, it should cancel the whole event:



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


This would be nice to be configurable in the constructor of the treepanel.

Though what wondered me more is if this functionality "was really meant to work like this(automatically select on right click)" or it just came out this way.

Regards, Andrei.