Hi,
I'm trying to do drag and drop between 2 treeview using example at http://demos.telerik.com/aspnet-ajax/treeview/examples/functionality/draganddropnodes/defaultvb.aspx
However, I do not want the item to be removed from the first tree view.
1. I removed the server side event and both my treeviews are as following:
<
telerik:RadTreeView
ID
=
"radTV_pages"
Font-Size
=
"Large"
runat
=
"server"
EnableDragAndDrop
=
"True"
OnClientNodeDropping
=
"onNodeDropping"
OnClientNodeDragging
=
"onNodeDragging"
MultipleSelect
=
"true"
EnableDragAndDropBetweenNodes
=
"true"
>
</
telerik:RadTreeView
>
<
telerik:RadTreeView
ID
=
"radTV_Menu"
Font-Size
=
"Large"
runat
=
"server"
EnableDragAndDrop
=
"True"
OnClientNodeDropping
=
"onNodeDropping"
OnClientNodeDragging
=
"onNodeDragging"
MultipleSelect
=
"true"
EnableDragAndDropBetweenNodes
=
"true"
>
</
telerik:RadTreeView
>
2. As for the client script, I modified as following (remove grid related code and comment "sourceNode.get_parent().get_nodes().remove(sourceNode);"):
<script>
(
function
() {
var
demo = window.demo = window.demo || {};
//demo.checkbox = document.getElementById('<%'= ChbClientSide.ClientID %>');
//function isMouseOverGrid(target) {
// parentNode = target;
// while (parentNode !== null) {
// if (parentNode.id === demo.grid.get_id()) {
// return parentNode;
// }
// parentNode = parentNode.parentNode;
// }
// return null;
//}
function
dropOnHtmlElement(args) {
if
(droppedOnInput(args))
return
;
if
(droppedOnGrid(args))
return
;
}
function
droppedOnGrid(args) {
var
target = args.get_htmlElement();
while
(target) {
if
(target.id === demo.grid.get_id()) {
args.set_htmlElement(target);
return
;
}
target = target.parentNode;
}
args.set_cancel(
true
);
}
function
droppedOnInput(args) {
var
target = args.get_htmlElement();
if
(target.tagName ===
"INPUT"
) {
target.style.cursor =
"default"
;
target.value = args.get_sourceNode().get_text();
args.set_cancel(
true
);
return
true
;
}
}
function
dropOnTree(args) {
var
text =
""
;
if
(args.get_sourceNodes().length) {
var
i;
for
(i = 0; i < args.get_sourceNodes().length; i++) {
var
node = args.get_sourceNodes()[i];
text = text +
', '
+ node.get_text();
}
}
}
function
clientSideEdit(sender, args) {
var
destinationNode = args.get_destNode();
if
(destinationNode) {
firstTreeView = demo.firstTreeView;
secondTreeView = demo.secondTreeView;
firstTreeView.trackChanges();
secondTreeView.trackChanges();
var
sourceNodes = args.get_sourceNodes();
var
dropPosition = args.get_dropPosition();
//Needed to preserve the order of the dragged items
if
(dropPosition ==
"below"
) {
for
(
var
i = sourceNodes.length - 1; i >= 0; i--) {
var
sourceNode = sourceNodes[i];
//huisheng - do not remove source
//sourceNode.get_parent().get_nodes().remove(sourceNode);
insertAfter(destinationNode, sourceNode);
}
}
else
{
for
(
var
j = 0; j < sourceNodes.length; j++) {
sourceNode = sourceNodes[j];
//huisheng - do not remove source
//sourceNode.get_parent().get_nodes().remove(sourceNode);
if
(dropPosition ==
"over"
)
destinationNode.get_nodes().add(sourceNode);
if
(dropPosition ==
"above"
)
insertBefore(destinationNode, sourceNode);
}
}
destinationNode.set_expanded(
true
);
firstTreeView.commitChanges();
secondTreeView.commitChanges();
}
}
function
insertBefore(destinationNode, sourceNode) {
var
destinationParent = destinationNode.get_parent();
var
index = destinationParent.get_nodes().indexOf(destinationNode);
destinationParent.get_nodes().insert(index, sourceNode);
}
function
insertAfter(destinationNode, sourceNode) {
var
destinationParent = destinationNode.get_parent();
var
index = destinationParent.get_nodes().indexOf(destinationNode);
destinationParent.get_nodes().insert(index + 1, sourceNode);
}
window.onNodeDragging =
function
(sender, args) {
var
target = args.get_htmlElement();
if
(!target)
return
;
if
(target.tagName ==
"INPUT"
) {
target.style.cursor =
"hand"
;
}
//var grid = isMouseOverGrid(target)
//if (grid) {
// grid.style.cursor = "hand";
//}
};
window.onNodeDropping =
function
(sender, args) {
var
dest = args.get_destNode();
if
(dest) {
//var clientSide = demo.checkbox.checked;
var
clientSide =
true
;
if
(clientSide) {
clientSideEdit(sender, args);
args.set_cancel(
true
);
return
;
}
dropOnTree(args);
}
else
{
dropOnHtmlElement(args);
}
};
}());
/* <![CDATA[ */
Sys.Application.add_load(
function
() {
// demo.grid = $find("<%'= RadGrid1.ClientID %>");
demo.firstTreeView = $find(
'<%=radTV_pages.ClientID%>'
);
demo.secondTreeView = $find(
'<%= radTV_Menu.ClientID%>'
);
//demo.checkbox = document.getElementById('<%'= ChbClientSide.ClientID %>');
});
/* ]]> */
</script>
3. However, the source node is still removed. How can I make the source target to remain?
Thanks.