PDA

View Full Version : TreeNode: deselect a node or I want to restrict a tree node from selecting it.



nareshkokkula
2 Apr 2012, 1:48 AM
Hi..Can some one help me in restricting a tree node to be not selected.I used the following code to deselect tree node in the beforeselect event.but its selecting with a ash colored line... var srcTree = Ext.create('Ext.tree.Panel', { title: 'Source Tree', width: 300, autoScroll: true, animate: true, enableDD: true, ddGroup: 'secondTreeDDGroup', multiSelect: true, containerScroll: true, region: 'center', store: store, viewConfig: { plugins: { ddGroup: 'selDD', ptype: 'treeviewdragdrop', enableDrop: false } }, listeners: { 'select': BeforeSelect } }); function BeforeSelect(rownModel, record, index, eOpts) { if (record.data.text == "Energy foods") { rownModel.deselect(index, true); } }Please help me.Thanks,33440Naresh

vietits
2 Apr 2012, 2:26 AM
You should listen on 'beforeselect' event instead of 'select' event.


var srcTree = Ext.create('Ext.tree.Panel', {
title: 'Source Tree',
width: 300,
autoScroll: true,
animate: true,
enableDD: true,
ddGroup: 'secondTreeDDGroup',
multiSelect: true,
containerScroll: true,
region: 'center',
store: store,
viewConfig: {
plugins: { ddGroup: 'selDD', ptype: 'treeviewdragdrop', enableDrop: false }
}, listeners: {
'beforeselect': function(rownModel, record){
return record.get('text') != 'Energy foods';
}
}
});

nareshkokkula
11 Apr 2012, 2:45 AM
I added the listeners for my tree control

listeners: {
'itemClick': ItemClick,
'itemmouseleave': ItemClick,
'itemmousedown': ItemClick,
'itemmouseenter': ItemClick
}

function ItemClick(view, record, item, index, e, eOpts) {
if (!selectWorkers && record.data.type == "Worker") {
view.deselect(record);
}
}
This deselects the node.

Can any one suggests better approach for this:)