dojo.dnd Elemente programmatisch zwischen Containern verschiebenProgrammatically move dojo.dnd items between containers

In order to programmatically move dojo.dnd items (dojo.dnd.Item) between containers (dojo.dnd.Container) you only need to insert existing nodes from the source container into the target container, delete any moved nodes from the source container and finally sync() both containers to update the underlying metadata.

The following code snippet should clarify this principle. It demonstrates that items are only moved from the source container if their value does not match an expected value:

//only moving items if expected value is not met
if (srcContainer.getItem(node.id).data != expectedValue) {                    
  targetContainer.insertNodes(false, [dojo.byId(node.id)]);
  targetContainer.sync();

  srcContainer.delItem(node.id);
  srcContainer.sync(); //sync nodes and metadata
}

Hint: dojo.dnd underlying principle is a separation between data and nodes. So whenever you alter one part of an dndItem (data or node) be sure to synchronize its state by calling sync(). See the official reference guide for more information: dojo.dnd package

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.