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

Is it possible to detect drop location

1 Answer 28 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 10 Sep 2010, 04:17 PM
If I have a dragable node on a RadTree is it possible to check the x/y location of where the node is dropped in respect to a panel?

So if I have a panel containing tree A, plus some other controls, I just want to know if the node I have dragged from tree B is over the panel containing tree A possibly changing the background colour of the panel to show that the node is over an area that it can be released?

I have tried using the following code to test the possibility out, but the domEvent.offsetX seems to keep changing what it is measuring from as I move it around.

<script type="text/javascript" language="javascript">
  
    function findPosX(obj) {
        var curleft = 0;
        if (obj.offsetParent)
            while (1) {
                curleft += obj.offsetLeft;
                if (!obj.offsetParent)
                    break;
                obj = obj.offsetParent;
            }
        else if (obj.x)
            curleft += obj.x;
        return curleft;
    }
  
    function findPosY(obj) {
        var curtop = 0;
        if (obj.offsetParent)
            while (1) {
                curtop += obj.offsetTop;
                if (!obj.offsetParent)
                    break;
                obj = obj.offsetParent;
            }
        else if (obj.y)
            curtop += obj.y;
        return curtop;
    }
  
    function ClientNodeDragging(sender, eventArgs) {
        var domEvent = eventArgs.get_domEvent();
        var node = eventArgs.get_node();
        var MyPanel;
        if (document.getElementById('<%= leftPanel.FindControl("pnlPositionSelector").ClientID %>') != null) {
            MyPanel = document.getElementById('<%= leftPanel.FindControl("pnlPositionSelector").ClientID %>');
            node.set_text("Dragging X:" + domEvent.offsetX + " Y:" + domEvent.offsetY + " target XPos=" + findPosX(MyPanel) + " target YPos=" + findPosY(MyPanel));
        }
        else {
            node.set_text("Dragging X:" + domEvent.offsetX + " Y:" + domEvent.offsetY);
        }
        //MyPanel.style.height = NewHeight + "px";
        //MyPanel.style.width = NewWidth + "px";
  
  
  
    }
</script>

1 Answer, 1 is accepted

Sort by
0
T. Tsonev
Telerik team
answered on 15 Sep 2010, 03:55 PM
Hi Jonathan,

Please look at the following demo - Drag-and-drop. It demonstrates how you can determine if the mouse is over a particular DOM element without calculating coordinates.

Check out the isMouseOverGrid function:

function isMouseOverGrid(target)
{
    parentNode = target;
    while (parentNode != null)
    {                   
        if (parentNode.id == gridId)
        {
            return parentNode;
        }
        parentNode = parentNode.parentNode;
    }
 
    return null;
}

You should be able to adapt it to your requirements.

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
TreeView
Asked by
Jonathan
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or