question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Drag & drop multiple node

See original GitHub issue

Hello,

I would like to drag and drop multiple leaf. I’ve activated the multi active tree options, and override the drop function (in the options.actionMapping) as follow :

drop: (tree, node, $event, { from, to }) => {
    const activeNodes = tree.getActiveNodes();
    if (activeNodes.length > 1) {
        activeNodes.forEach(item => {
            tree.moveNode(item, to);
        });
    } else {
        tree.moveNode(from, to);
    }
}

But it raises an arror if we try to move two nodes from the same parent. I found a workaround : in the tree.model.js, in the move function, I’ve replaced

var fromIndex = node.getIndexInParent();
var fromParent = node.parent;
if (!this._canMoveNode(node, fromIndex, to))
    return;
var fromChildren = fromParent.getField('children');

by

var fromParent = node.parent;
var fromChildren = fromParent.getField('children');
var fromIndex = fromChildren.findIndex(item => item.id == node.id);
if (!this._canMoveNode(node, fromIndex, to))
    return;

Maybe not the best solution, as it will recalculate the node position in his parent each time.

By the way, it would be great to add an “allowMultipleActive” option. It would be useful to avoid to select different kinds of node (for example, I active a leaf, I would like to prevent to activate a node with children)

Thanks for your work !

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
ulymorcommented, Feb 8, 2019

Does it exist any way to drag and drop several nodes together? I have tried to select two nodes (via pressed Ctrl key) and move them but as a result I have got js error and only one node has been moved. I have used the same approach like @elzebu But changes in code didn’t help because on second call of function node.parent equals to null.

To reproduce select at least two nodes via pressed Ctrl key and try to Drag and Drop them. https://stackblitz.com/edit/angular-6ys7sc

0reactions
DmitriyKomelkovcommented, Apr 23, 2020

@ulymor @ebouvi01 You can implement this feature without error by some change code of @marekalgoud :

drop: (tree, node, $event, { from, to }) =>
        {
          const activeNodes = tree.getActiveNodes();
          if (activeNodes.length > 1) {
            activeNodes.forEach(item => {
              const currentItem = tree.getNodeById(item.id);
              tree.moveNode(currentItem, to);
            });
          } else {
            tree.moveNode(from, to);
          }
        }

Pls pay attention you do not have to change tree.model.js.

Read more comments on GitHub >

github_iconTop Results From Across the Web

TreeList - How to drag and drop multiple nodes
In recent versions, TreeList supports the capability to drag and drop multiple nodes out of the box. For this, set the ...
Read more >
Drag drop of multiple nodes only shows one node in args
Hi,. When i drag multiple nodes in the treeview only one node is processed. So it looks like all the nodes are dragged...
Read more >
Allow Drag and Drop of Multiple Nodes in Tree View. - MSDN
I have supported single node drag and drop,but how can the multiple nodes be selected and dropped to another node. 2.) While dragging/dropping ......
Read more >
Drag & drop multiple node · Issue #548 - GitHub
To reproduce select at least two nodes via pressed Ctrl key and try to Drag and Drop them. https://stackblitz.com/edit/angular-6ys7sc ...
Read more >
Dragging and Dropping Tree Nodes - L3HarrisGeospatial.com
Drag and drop-related properties of a tree widget node (the values of the DRAG_NOTIFY, DRAGGABLE, and DROP_EVENTS keywords) are inheritable. This means that ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found