Follow-up on TreePanel

In this post, I had the following questions:

  • How do I set leaf node?
  • How do I configure to change the initial “move” behavior of drag-and-drop into a “copy” action so the node in the source tree doesn’t disappear?

Here are my own answers:

To set leaf node, I just updated the sandbox function to return an array of node definition objects instead of simple text. For example, a leaf node definition can look like the following:


To convert a “move” to a “copy” behavior, I had to listen on “beforeremove” event and call appendchild() function with a new Ext.tree.AsyncTreeNode object. The new node object contains data from the original node. This effectively undo remove operation. I added in an extra if statement for situations when I actually want to remove a node.

Beyond that, I also wanted to add the ability to not add duplicate nodes. So, I had to listen on “beforenodedrop” event and call findChild() function to find matching node based on text attribute. If the function returns a non-null object, then I called remove function. The code will continue add the node and the net result will be a single node, which is what I wanted.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s