[zTree] Save sort drag and drop Ztree Component
ztree
Forge component by Eduardo Luís

Hello guys!

Have you used the Drag and Drop property of the Ztree component?

In my structure I have a property called ORDER, this property will store the order of each parent node in my tree.


[Node 1: ORDER = 1

  Node 2: ORDER = 2

  Node 3: ORDER = 3

  Node 4: ORDER = 4]


After moving any node up or down, I would like to get the node value and thus save that new position value in my ORDER property.

Currently I can already have Drag and Drop. What happens... that is not saving the position.

Do you have any experience of how I can implement with ztree?

cat.png

Solution

Hi Danilo,

I implemented an example of how to get the element that is being dragged and where it was dropped.

See the attached oml.

Changes were made to the beforeDrop callback settings.



zTreeDragAndDrop.oml

Hi!

Thanks for the reply and help.

I am following a logic to save the position of the nodes in my table as follows.


X = Current node

Y = Next node


Given a node list:


- Node 1

- Node 2

- Node 3

- Node 4

- Node 5


I will drag the node to a certain position in the tree. After drop the node.

I will capture the successor node to node which is node Y.

With this I will do Y - 1, then, I will store in my table what the new position of node X is.

In the demo of the ZTree component, I have an example of how I use the OnClick function and capture the node.

I'm not able to do to get the value of the Y node.



Do you have any idea how I can capture this ID or any other suggestions?



I managed to follow this logic that I was wanting. Now I need to think about how I will order the tree using my ORDER property, without breaking the ZTreeData structure.


Thank you for your help!

I am using the traditional web.

Solution

Hi Danilo,

I implemented an example of how to get the element that is being dragged and where it was dropped.

See the attached oml.

Changes were made to the beforeDrop callback settings.



zTreeDragAndDrop.oml

Hi!

Thanks for the reply and help.

I am following a logic to save the position of the nodes in my table as follows.


X = Current node

Y = Next node


Given a node list:


- Node 1

- Node 2

- Node 3

- Node 4

- Node 5


I will drag the node to a certain position in the tree. After drop the node.

I will capture the successor node to node which is node Y.

With this I will do Y - 1, then, I will store in my table what the new position of node X is.

In the demo of the ZTree component, I have an example of how I use the OnClick function and capture the node.

I'm not able to do to get the value of the Y node.



Do you have any idea how I can capture this ID or any other suggestions?



I managed to follow this logic that I was wanting. Now I need to think about how I will order the tree using my ORDER property, without breaking the ZTreeData structure.


Thank you for your help!

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.