View Full Version : Tree: move node with DnD on a leaf node does not work (appendchild)

8 Dec 2011, 2:58 AM
I have the following tree :

- node A
- node B
- node C
- node C1
- node C2
- node D

I've configured my tree with a treeviewdragdrop plugin and implemented beforedrop event.

If I DnD node D on node C, it works perfectly.
My issue is when I try to DnD a node to a leaf node: it does not work at all !
For example:
- DnD node B on node A : not working
- DnD node C2 on node C1 : not working

I've tried to force target node leaf property to false but it changes nothing.

Here is my beforedrop event function :

beforeDropCategory: function(node, data, model, pos, drop) {
console.log('CategoriesPanel::beforeDropCategory: start');
var rec = data.records[0];
model.set('leaf', false);
console.log('model', model);
console.log('CategoriesPanel::beforeDropCategory: done');

after calling appendChild, I can notice into debug console that model childNodes array is empy.

Thanks for your help

8 Dec 2011, 5:08 AM
Does this work?

node.data.leaf = false;

8 Dec 2011, 5:44 AM
I didn't mention it but I've also tried this and unfortunately it does not help :((

8 Dec 2011, 6:09 AM
And if you set the leaf to false first and then append

model.set('leaf', false);

8 Dec 2011, 6:17 AM
no change /:)

8 Dec 2011, 6:42 AM
Maybe you should firebug this one.. and go into the infinity of ExtCode... at breakpoint appendChild() B)

9 Dec 2011, 3:01 AM
First of all, thanks for your answers.

I ran through the firedebug and finally, it seems that the appendChild event is correctly performed.
Node B is correctly added to node A children list.
The issue seems to be at the tree view display level.

I've didn't notice it at the beginning but something looks strange. When I DnD my Node B on node A, the "add" icon (plus sign) is not displayed.
If I do it again (so two DnD of node B on node A), this time I have the "add" icon and it works.

I'm a bit lost now :)

9 Dec 2011, 3:58 AM
From the docs of TreeView.

refresh( )
Refreshes the grid view. Saves and restores the scroll state, generates a new template, stripes rows and invalidates the scrollers.

Maybe that helps if you are able to get that treeview from the tree.

9 Dec 2011, 8:48 AM
Doing a refresh on the view doesn't help.

In fact, as I was previously saying, I think the issue is before the beforedrop event is fired.
Indeed, when I click a node (let's say node B) and drag it on another node which is a leaf, the "add" operation is not possible (no "add" icon displayed).

But doing it a first time, it calls my beforedrop event function that set the node A leaf property to false.
By this way, the second time I try to drag and drop my node, it works.

Now, the question is why can't add it at the first time

I am clear in my explanation (not sure)? /:)

9 Dec 2011, 9:46 AM
You are clear in your explanation. But I don't know why it happens. Maybe you should post some testcase .... are you using the TreeViewDragDrop plugin? Or how is your DD implementation done?

The only other solution I see on the forum wich you may try is to do the set on the node instead of the model

node.set('leaf', false);

But probably it will not make a difference....

16 Dec 2011, 8:07 AM
I had the same problem. This hack worked for me:

var m = parentNode.createNode(configNewNode);
m.internalId = m.getId();
parentNode.insertChild(0, m); // or parentNode.appendChild(m);