PDA

View Full Version : Restricting node drop to parents



SABoffin
7 Dec 2009, 3:42 AM
For example, looking at the api documentation;

All the leafs in the tree node should be droppable within tree and nowhere else and the same should occur for every onther 'folder'. This should also happen to any depth so for instance is tree had another node underneath that acts as folder with a number of leafs within it you should be able to drag those leafs anywhere within the tree node.

Basically I'm looking for a method of setting ddgroups up on the fly with no prior knowledge of the data other than there will be a number of root folders with a number of folders and leafs within those root forlders. Anything can move anywhere within its root folder but not ourside of that root.

Hope that makes sense! Any pointer appreciated
Thanks
Simon

7 Dec 2009, 6:11 AM
I cover a similar restriction of DnD in my book (see sig below).

Here's the example.

http://extjsinaction.com/examples/chapter14/dnd_tree_to_tree.html

Notice that you can only drop an 'accounting' node on another 'accounting' group or similar (finances) group.

MiamiCoder
7 Dec 2009, 6:13 AM
You can use the nodedragover event to determine if the user can move the folder to a given node. One way to know that a group of folders belong in the same container would be to use a certain naming pattern for their id's, for example:
parent1
parent1-child1
parent1-child2
...
parent2
parent2-child1

csky
8 Dec 2009, 8:45 AM
Is there a way to restrict the drop to the folder node itself? I want to prevent users from dropping a source before, after or in between child nodes. So, in the ExtJS in Action example, I only want to be able to drop employees on to the "Accounting" folder.

8 Dec 2009, 8:48 AM
Yes you can. If you read the source, it's all detailed. If you want a detailed explanation on the source, then I would like to suggest getting the book :)

SABoffin
8 Dec 2009, 8:51 AM
Thankyou both for the replies, after reading your thoughs/code I have changed my json so each node carries a parent id attribute that I then use as a comparator on the events fired by the tree drag and drop events.

It's still a work in progress but you both helped me in the right direction.

Many thanks
Simon

ps. @ jgarcia - Is your book finished yet I've been following its progress on and off for a while, will be grabbing a copy as and when I can!

csky
8 Dec 2009, 8:57 AM
Yes you can. If you read the source, it's all detailed. If you want a detailed explanation on the source, then I would like to suggest getting the book :)

I'm asking Santa for the book :)

My question is slightly different than what the example shows. For instance, if the Accounting folder contained "Avery, Amity" and "Salinas, Erin" I want to force the user to drop "Ryan, Gareth" on the Accounting folder. I do not want them to be able to insert "Ryan, Gareth" before, after or in between the two existing accounting employees.

csky
8 Dec 2009, 10:58 AM
Yes you can. If you read the source, it's all detailed. If you want a detailed explanation on the source, then I would like to suggest getting the book :)

You're right ... it is in there! Thanks.