PDA

View Full Version : TreePanel beforeremove event doesn't work



aj3423
4 Sep 2010, 10:32 AM
tree.on('beforeremove', function(tree, parent, node) {
return false;
});

API says return false to cancel the remove, but the node is always removed from the Gui, but the data node in memory is not removed.
in the TreeNode.js I found:

// private override
removeChild : function(node, destroy){
this.ownerTree.getSelectionModel().unselect(node);
Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments);
// only update the ui if we're not destroying
if(!destroy){
// if it's been rendered remove dom node
if(node.ui.rendered){
node.ui.remove();
}
should it be:

// private override
removeChild : function(node, destroy){
if(Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments) === false) return false;
this.ownerTree.getSelectionModel().unselect(node);
// only update the ui if we're not destroying
if(!destroy){
// if it's been rendered remove dom node
if(node.ui.rendered){
node.ui.remove();
}
?

laurentParis
4 Sep 2010, 10:49 PM
Event called by fireEvent


removeChild: function (node, destroy) {
if(this.fireEvent('beforeremove', this.ownerTree, this, node) !== false) {
.... //remove code
}
}

aj3423
4 Sep 2010, 11:04 PM
the beforeremove event is handled in Ext.data.Node, but not in Ext.tree.TreeNode, so the tree node is removed from Gui but the data node is still in memory.

laurentParis
4 Sep 2010, 11:29 PM
when you call removeChild, why your not post true for "destroy" argument ?

If you would pass over like you're sugest on your 'should it be', I reformule at your convenance )


removeChild : function(node, destroy){
if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false) return false;
...
}


Ext.tree.TreeNode extend Ext.data.Node... so it's ok !

aj3423
5 Sep 2010, 8:48 AM
when you call removeChild, why your not post true for "destroy" argument ?

If you would pass over like you're sugest on your 'should it be', I reformule at your convenance )


removeChild : function(node, destroy){
if(this.fireEvent("beforeremove", this.ownerTree, this, node) === false) return false;
...
}


Ext.tree.TreeNode extend Ext.data.Node... so it's ok !
Oh, I see, the tricky is the 'destroy' argument
Thanks a lot ~;)