This is a migrated thread and some comments may be shown as answers.

[Solved] Dragging to parent node

2 Answers 101 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jaymie
Top achievements
Rank 1
Jaymie asked on 25 Nov 2011, 12:19 PM
Hi :)

I am having a bit of an issue with the TreeView draggable nodes.
I have a treeView that looks like the attached image.

I can drag and drop the different nodes where I please.
I don't want to be able to drag anything inline with the "Home" category, but I do want to be able to drag it to be the child...
I added this code:

function onNodeDrop(e) {
    var dropContainer = $(e.dropTarget).closest('.drop-container');
    var treeview = $('#TreeView').data('tTreeView');
    var parentId = treeview.getItemValue(e.destinationItem);
    var firstNodeElement = treeview.getItemValue($("li:first", treeview.element)[0]);
    var nodeText = treeview.getItemText(e.item);
    if (parentId == firstNodeElement) {
        e.preventDefault();
    }
    if (dropContainer.length > 0 && dropContainer[0].innerHTML.indexOf(nodeText) == -1) {
        $('<div><strong>' + nodeText + '</strong></div>')
            .hide().appendTo(dropContainer).slideDown('fast');
        e.preventDefault();
    }
}

which stops me putting any nodes next to the "Home" node, but it also stops me being able to add any children.
Could someone please let me know how to add child nodes to the "Home" node, but disable dragging nodes to it's level?

Cheers,
/Jaymie

2 Answers, 1 is accepted

Sort by
0
Jaymie
Top achievements
Rank 1
answered on 28 Nov 2011, 03:37 PM
Anyone got any ideas?
0
Jaymie
Top achievements
Rank 1
answered on 30 Nov 2011, 12:25 PM
Well,
Incase anyone else has this problem, here is the answer:

if (parentId == firstNodeElement && e.dropPosition == "before") {
    e.preventDefault();
}
Tags
TreeView
Asked by
Jaymie
Top achievements
Rank 1
Answers by
Jaymie
Top achievements
Rank 1
Share this question
or