jQWidgets Forums

jQuery UI Widgets Forums Navigation Tree DragDrop how to keep the item?

This topic contains 3 replies, has 2 voices, and was last updated by  Dimitar 10 years, 8 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • DragDrop how to keep the item? #58214

    Stanoweb
    Participant

    Hello,
    I use 2 trees one for the recipient items (drop) and one for the source items (drag).
    I would like, when I drop an item, to keep it from the source tree.
    Is it possible? and if yes how?
    Thanks for your help.

    DragDrop how to keep the item? #58225

    Dimitar
    Participant

    Hello Stanoweb,

    This is possible if you set the first tree’s dragEnd callback as follows (note that it has to return false):

    $('#treeA').jqxTree({ allowDrag: true, allowDrop: true, height: '300px', width: '220px',
        dragEnd: function (dragItem, dropItem, args, dropPosition, tree) {
            switch (dropPosition) {
                case "inside":
                    $('#treeB').jqxTree('addTo', dragItem, dropItem);
                    break;
                case "before":
                    $('#treeB').jqxTree('addBefore', dragItem, dropItem);
                    break;
                case "after":
                    $('#treeB').jqxTree('addAfter', dragItem, dropItem);
                    break;
            }
            return false;
        }
    });

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

    DragDrop how to keep the item? #58234

    Stanoweb
    Participant

    Thanks.. I will try it..
    What I did was to save the source of the treeA into a temp variable and after adding the node to the treeB, set back the source to the treeA.
    Something like this, based on your code :
    $(‘#treeA’).jqxTree({ allowDrag: true, allowDrop: true, height: ‘300px’, width: ‘220px’,
    dragEnd: function (dragItem, dropItem, args, dropPosition, tree) {
    var tempSource= $(‘#treeA’).jqxTree(‘source’)
    switch (dropPosition) {
    case “inside”:
    $(‘#treeB’).jqxTree(‘addTo’, dragItem, dropItem);
    break;
    case “before”:
    $(‘#treeB’).jqxTree(‘addBefore’, dragItem, dropItem);
    break;
    case “after”:
    $(‘#treeB’).jqxTree(‘addAfter’, dragItem, dropItem);
    break;
    }
    $(‘#treeA’).jqxTree({source: tempSource});
    return true;
    }
    });

    DragDrop how to keep the item? #58249

    Dimitar
    Participant

    Hello Stanoweb,

    You do not need to implement this. Returning false cancels the changes to the first tree anyway.

    Best Regards,
    Dimitar

    jQWidgets team
    http://www.jqwidgets.com/

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.