2

enter image description here

I am using JQXTree, A sample Html code

<div id='treeA' style='float: left; margin-left: 0px;'>
<ul>
    <li id='home' item-selected='true'>Server</li>
        <li item-expanded='true'>Incoming Data
            <ul>
            <li>FTP Adapter</li>
            <li item-expanded='true'>RDBMS
            <ul>
                         <li draggable="true">ftpConnection1</li>
                         <li id='ftpConnection2'>ftpConnection2</li>
            </ul>
        </li>
    <li>NoSql Adapter</li>
    <li>RSS Adapter</li>
    <li>MQTT Adapter</li>
    <li>ZMQ Adapter</li>
    </ul>
   </li>
 </ul>
</div>

$('#treeA').jqxTree({ allowDrag: true, allowDrop: true,  theme: theme});

In Image if I drag ftpConnection1 i need to get the Parent Id that is FTP Adapter and also its Parent's Id that is Incoming Data.

I use dragEnd event on the tree

$("#treeA").on('dragEnd', function (item) {  
            console.log(item);
       var droppedToolId = item.args.owner._dragItem.id;
       var parentId = item.args.owner._dragItem.parentId;
});

So I get the Parent Id, I need to get the Parent’s Parent Id for the item i drop.

Any suggestions?

Sri
  • 1,505
  • 2
  • 18
  • 35

2 Answers2

0

I hope you have no duplicate ids Try

$("#treeA").on('dragEnd', function (item) {  
            console.log(item);
       var droppedToolId = item.args.owner._dragItem.id;
       var parentId = item.args.owner._dragItem.parentId;
       var Pid = $('#'+parentId).parent().attr('id');//get parent
       alert(Pid);
});
Nouphal.M
  • 6,304
  • 1
  • 17
  • 28
0

Try this code snippet:

$('#treeA').jqxTree({ allowDrag: true, allowDrop: true, height: '300px', width: '220px', 
                dragEnd: function (item, dropItem, args, dropPosition, tree) {
                    if (item.level != dropItem.level && item.parentId != dropItem.parentId)
                        return false;
                }   
                oldParentId = item.parentId;
                newParentId = dropItem.parentId;          
        });

hope this helps!

Ace
  • 821
  • 3
  • 16
  • 37