PDA

View Full Version : Treepanel right click disable node selection



klodoma1
22 Aug 2012, 12:10 PM
Hi,

On right click the node in the treepanel is automatically selected.
Is there a way/workaround to disable this behavior?

Thanks.

sword-it
22 Aug 2012, 11:11 PM
Hi klodoma1,

You can achieve this by deselect(index) method of Ext.selection.Model, like


Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
listeners:{
itemcontextmenu:function(panel, record, item, index, e){
this.getSelectionModel().deselect(index);
}
},
renderTo: Ext.getBody()
});


Here is working sample example -http://jsfiddle.net/nVwwD/

klodoma1
22 Aug 2012, 11:25 PM
No, that is not really what I want cause the selected not gets deselected.

I would like with right click not to be able to select a node, I've tried to reject all some of click events but haven't found a solution yet.

redraid
22 Aug 2012, 11:27 PM
Its simple:
http://docs.sencha.com/ext-js/4-1/#!/api/Ext.selection.RowModel-cfg-ignoreRightMouseSelection (http://docs.sencha.com/ext-js/4-1/#!/api/Ext.selection.RowModel-cfg-ignoreRightMouseSelection)


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 }
]
}
});

Ext.create('Ext.tree.Panel', {
title: 'Simple Tree',
width: 200,
height: 150,
store: store,
rootVisible: false,
renderTo: Ext.getBody(),
selModel: {
ignoreRightMouseSelection: true // Disable right click selection
}
});

redraid
22 Aug 2012, 11:29 PM
This also works for the grid

klodoma1
22 Aug 2012, 11:44 PM
YES! This is it. Thanks a lot!