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

drop parent on child node event

3 Answers 71 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Justin
Top achievements
Rank 1
Justin asked on 11 Jun 2013, 12:49 AM

Hi,

I am not able to trigger the "OnClientNodeDropping"  event when a parent node is dropped onto a child node. This is required in order to execute some custom code for cloning the parent node and adding it as a child. In the attached example, I have had to use a customised picker tool to add the parent node "Everyone" to its child "My Team". This is fine for a example, but not a practical solution.

I have tried using the method described in the below link to get the target node that the parent is dropped onto. However this will not give me the target node attributes only the html element of the node.
http://www.telerik.com/community/forums/aspnet-ajax/treeview/dropping-a-node-on-itself-doesn-t-fire-events.aspx

Am I missing an attribute in the Telerik control ? (I have both EnableDragAndDrop and EnableDragAndDropBetweenNodes set to true), or is there something else I should be doing?

Thanks
Justin

3 Answers, 1 is accepted

Sort by
0
Kevin
Top achievements
Rank 2
answered on 12 Jun 2013, 08:52 PM
Hello Justin,

Have you tried using the OnClientNodeDropped or OnClientNodeDropping? As these events give you the node that is being dropped.
0
Justin
Top achievements
Rank 1
answered on 13 Jun 2013, 12:06 AM
Hi Kevin,

Many thanks for your reply.

Both the OnClientNodeDropped and OnClientNodeDropping are firing for dropping parent nodes onto other "peer" parent nodes, and child nodes on and between other nodes, but they are not firing when a parent node is dropped onto one of its child nodes as I mentioned in my initial post, which is important functionality for our current project.

How can I access the events in the scenario of dropping a parent node onto one of its child nodes?

Thanks again for your help

Justin
0
Boyan Dimitrov
Telerik team
answered on 13 Jun 2013, 10:21 AM
Hello Justin,

Your observations are absolutely correct and the OnClientNodeDropping and OnClientNodeDropped events are not fired when user tries to drop a parent node to one of its child items. Therefore I have prepared a workaround in order to implement such functionality:
//markup code
<telerik:RadTreeView runat="server" ID="RadTreeView1" EnableDragAndDrop="true" OnClientNodeDragStart="dragStart">
    <Nodes>
        <telerik:RadTreeNode Text="Node 1" />
        <telerik:RadTreeNode Text="Node 2">
            <Nodes>
                <telerik:RadTreeNode Text="Node 2.1" />
                <telerik:RadTreeNode Text="Node 2.2" />
                <telerik:RadTreeNode Text="Node 2.3" />
            </Nodes>
        </telerik:RadTreeNode>
        <telerik:RadTreeNode Text="Node 3" />
    </Nodes>
</telerik:RadTreeView>

//JavaScript
function dragStart(sender, args) {
    dragging = false;
 
    $(document).bind("mouseup", function (e) {
        var sourceNode = args.get_node();
        var sourceNodeElement = sourceNode.get_element();
        var droppedNodeDomElement = $telerik.$(e.target).closest('li')[0];
        if ($telerik.isDescendantOrSelf(sourceNodeElement, droppedNodeDomElement)) {
             
            var clonedNode = sourceNode.clone();
             
            droppedNodeDomElement._item.get_nodes().add(clonedNode);
        }
        $(document).unbind("mouseup", arguments.callee);
        dragging = false;
    });
}

Please note that this custom code will be executed only if you are trying to drop a parent element on one of its child items.

Regards,
Boyan Dimitrov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
TreeView
Asked by
Justin
Top achievements
Rank 1
Answers by
Kevin
Top achievements
Rank 2
Justin
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or