Get Parent's Parent Id in jqxtree drag in dragEnd Event

1.3k Views Asked by At

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?

2

There are 2 best solutions below

0
On

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);
});
0
On

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!