angular-tree-component icon indicating copy to clipboard operation
angular-tree-component copied to clipboard

Drag external element into tree

Open musti2 opened this issue 7 years ago • 4 comments

Hi Team,

Please provide an example as to how to drag an external element into the tree.

The documentation only states to provide a custom handler, but do i need to create a new TreeNode from the external element? If this has been answered at some point, with an example or some further guidance, please do let me know,

musti2 avatar Feb 04 '18 23:02 musti2

same issue

aldrindizonh avatar Mar 07 '18 07:03 aldrindizonh

how to determine if the nodes is coming in external tree?

aldrindizonh avatar Mar 07 '18 07:03 aldrindizonh

@musti2 Hi where you able to find out how to do it? BR

ExFlo avatar Apr 23 '20 15:04 ExFlo

I suggest to create a function createNode that can be used in the mapping drop callback to ease the job of node creation. By looking at the implementation of moveNode I was able to create the node like this

actionMapping: {
  mouse: {
    drop: (tree, node, $event, {from, to}) => {
      // tree.createNode(from, to);  in the futur?
      if (!to.parent.getField('children')) {
        to.parent.setField('children', []);
      }
      const toChildren = to.parent.getField('children');
  
      // here my from is { 
      //   id: 8,
      //   name: 'Parent 8'
      // }
      // so it does have an id but you can use your getNodeClone to generate a
      // new node with a unique ID
      toChildren.splice(to.index, 0, from);

      tree.update()
    }
  }
}

ExFlo avatar Apr 24 '20 09:04 ExFlo