# EasyTree - Reihenfolge der Knoten ändern



## neela (9. Jun 2017)

Hallo, 

ich möchte mittels Drag and Drop die Reihenfolge der Knoten ändern. Für die Darstellung des Baumes verwende ich EasyTree.

Aktuell gelingt es mir nur die Elemente zwischen den Parents zuverschieben. Dabei werden sie immer am Ende angefügt. 
Ist es euch bereits gelungen mittels EasyTree die Anordung der der Subelemente zu verändern?


----------



## neela (9. Jun 2017)

```
function drag(a) {
            if (!E.dragok) {
                return
            }
            if (!B.enableDnd) {
                return
            }
            if (E.createClone) {
                if (!E.clone) {
                    E.clone = createClone(E.sourceEl);
                    $(E.clone).appendTo('body')
                }
                E.clone.style.left = (a.pageX + 5) + "px";
                E.clone.style.top = (a.pageY) + "px"
            }
            var b = getDroppableTargetEl(a.clientX, a.clientY);
            if (!b) {
                hideDragHelpers();
                E.targetEl = null;
                E.targetId = null;
                E.targetNode = null;
                E.canDrop = false;
                return
            }
            if (b.id == E.targetId) {
                return
            }
            E.canDrop = false;
            window.clearTimeout(E.openDelayTimeout);
            E.targetEl = b;
            E.targetId = b.id;
            E.targetNode = getNode(D, E.targetId);
            log('source:'
                    + (E.sourceNode && E.sourceNode.text ? E.sourceNode.text
                            : E.sourceId));
            log('target:'
                    + (E.targetNode && E.targetNode.text ? E.targetNode.text
                            : E.targetId));
            log('isAncester:' + isAncester(E.sourceNode, E.targetId));
            var c = $('#' + E.targetId);
            if (isAncester(E.sourceNode, E.targetId)) {
                showRejectDragHelper();
                return
            }
            if (E.targetId == E.sourceId) {
                hideDragHelpers();
                return
            }
            if (B.canDrop) {
                var d = E.sourceNode != null;
                var e = d ? E.sourceNode : E.sourceEl;
                var f = E.targetNode != null;
                var g = f ? E.targetNode : E.targetEl;
                var h = B.canDrop(a, D, d, e, f, g);
                if (h === true) {
                    showAcceptDragHelper();
                    E.canDrop = true;
                    E.openDelayTimeout = window.setTimeout(function() {
                        openCloseNode(D, E.targetId, 'open');
                        renderNode(E.targetNode, 'open')
                    }, 600);
                    return
                } else if (h === false) {
                    showRejectDragHelper();
                    return
                }
            }
            if (c.hasClass('easytree-reject')) {
                showRejectDragHelper()
            } else if (c.hasClass('easytree-accept')) {
                showAcceptDragHelper();
                E.canDrop = true;
                E.openDelayTimeout = window.setTimeout(function() {
                    openCloseNode(D, E.targetId, 'open');
                    renderNode(E.targetNode, 'open')
                }, 600)
            } else {
                hideDragHelpers()
            }
            return false
        }
        function dragEnd(a) {
            var b = E.sourceNode != null;
            var c = b ? E.sourceNode : E.sourceEl;
            var d = E.targetNode != null;
            var e = d ? E.targetNode : E.targetEl;
            var f = E.canDrop;
            hideDragHelpers();
            $('#_st_clone_').remove();
            if (c === null || e === null) {
                resetDnd(E);
                return false
            }
            if (B.dropping) {
                var g = B.dropping(a, D, b, c, d, e, f);
                if (g === false) {
                    resetDnd(E);
                    return
                }
            }
            if (E.targetNode && E.sourceNode && f) {
                if (!E.targetNode.children) {
                    E.targetNode.children = []
                }
                removeNode(D, E.sourceId);
                E.targetNode.children.push(E.sourceNode)
            }
            if (f) {
                if (B.dropped) {
                    B.dropped(a, D, b, c, d, e)
                }
                buildTree(D)
            }
            resetDnd(E);
            return false
        }
```


----------

