I want to represent the dhtmlx tree order on a server as a directory tree. To do this I need to determine where a node has been “dragged from” and “dropped into” ie to redo the order on the server.
I’ve seen a tree events example using an on drag (tondrag) handler but that only has parameters for the node being dragged (eg dir1/file1) and the node into which the drop occurs (eg if at same level dir1/).
To represent the dhtmlxTree order in the directory tree on the server is of course a problem and the only way I can see to do this is to prepend the names eg
1:file5
2:file3
and remove the prepended number+colon when building the xml for loading into the dhtmlxTree.
So when a drag-n-drop occurs I need to know eg 2:file3 has moved above 1:file5 to give
1:file3
2:file5
And if dragged to a different dir eg move dir1 2:file2 to 2: in dir2
dir1/
1:file1
2:file2
3:file3
dir2/
1:file6
2:file7
then one dir will need to be compacted egand the other expanded ie
dir1/
1:file1
2:file3
dir2/
1:file6
2:file2
3:file7
Open to better suggestions
As far as I understod you need to know the item index before drag-n-drop and after it.
There is getIndexById method. You can call it inside onDrag and onDrop event handlers to get start and new indexes correspondingly:
tree.attachEvent(“onDrag”,function(sid){
alert("an index before d-n-d is "+tree.getIndexById(sid));
return true
})
tree.attachEvent(“onDrop”,function(sid,tid){
alert("the new index is "+tree.getIndexById(sid));
})