PDA

View Full Version : TreePanel 'beforenodedrop' event occur twice



ajang
24 May 2011, 10:21 PM
I have a problem handling event 'beforenodedrop' in TreePanel. The event occur twice. Below is my code :

beforenodedrop : function(e){
alert('e.dropNode.id');
}

skirtle
28 May 2011, 7:49 AM
It only fires once for me. I tried to reproduce your error with the following code, it might be interesting to see whether it works with whatever version of ExtJS you're using:


Ext.onReady(function() {
var root = new Ext.tree.TreeNode({text: 'root'});

root.appendChild(new Ext.tree.TreeNode({text: 'node 1'}));
root.appendChild(new Ext.tree.TreeNode({text: 'node 2'}));

new Ext.tree.TreePanel({
enableDD: true,
height: 300,
renderTo: Ext.getBody(),
root: root,
width: 300,

listeners: {
beforenodedrop: function() {
// alert('drop');
console.log('drop');
}
}
});
});

Perhaps you could come up with a more complete test case so that we can reproduce your problem? ExtJS version and browsers tested may also help.

One guess is maybe you're registering the listener twice rather than the event firing twice? I'd also advise that you stay clear of alert() for debugging, it can cause havoc with the JS threading model and introduce subtle errors that don't occur under any other circumstances.

ajang
7 Jun 2011, 2:31 AM
Sorry I was wrong. I use TreeGrid Panel not Tree Panel. Here is my code :


var routingTreeGrid = new Ext.ux.tree.TreeGrid({
id : 'routingTreeGrid',
title : '',
height : Ext.getCmp('machSchShowRoutingWindowBody').getHeight(),
width : Ext.getCmp('machSchShowRoutingWindowBody').getWidth(), resizable : false,
renderTo : Ext.getCmp('machSchShowRoutingWindowBody').body,
selModel : new Ext.tree.DefaultSelectionModel(),
enableSor : false,
enableDD : true,
ddGroup : 'machSchGrid2Tree',
columns :[
{
header : 'Task',
dataIndex : 'task',
width : 380
},
{
header : 'Duration',
width : 80,
dataIndex : 'duration',
align : 'center',
sortType : 'asFloat',
tpl : new Ext.XTemplate('{duration:this.formatHours}', {
formatHours: function(v) {
if(v < 1) {
return Math.round(v * 60) + ' mins';
} else if (Math.floor(v) !== v) {
var min = v - Math.floor(v);
if(min > 0){
return Math.floor(v) + 'h ' + Math.round(min * 60) + 'm';
}else{
return Math.floor(v) + 'h';
}
} else {
return v + ' hour' + (v === 1 ? '' : 's');
}
}
})
},
{
header : 'Progress',
width : 80,
dataIndex : 'progress',
align : 'center',
tpl : new Ext.XTemplate('{progress:this.formatProgress}', {
formatProgress: function(v) {
return v + ' %';
}
})
},
{
header : 'QTY',
dataIndex : 'qty',
width : 40,
align : 'center',
tpl: new Ext.XTemplate('{qty:this.formatQty}', {
formatQty: function(v) {
if(v != null || 'undefined' != v){
return v;
}else{
return 0;
}
}
})
}
],
loader: new Ext.ux.tree.TreeGridLoader({
dataUrl: '/csmerp/output/ppic/routing.php',
listeners: {
beforeload: function(treeLoader, node){
this.baseParams.order_no = Ext.getCmp('routeParts_part_noAutoCompleteCombo').getValue();
//this.baseParams.pos = node.attributes.pos;
this.baseParams.part_no = node.attributes.part_no;
},
load: function(treeLoader, node, response){
if(node.isLeaf() == false){
node.expand(true);
}
}
}
}),
tbar: {
items: [
"Order No. : ", routeParts_part_noAutoCompleteCombo,
'-',
new Ext.Toolbar.TextItem({
id : 'routingTreeGridReqDate',
text: ''
}),
'-',
new Ext.Toolbar.TextItem({
id : 'routingTreeGridQty',
text: ''
})
]
},
listeners : {
beforenodedrop : function(e){
console.log('beforenodedrop');
}
}
}).show();