Drag-and-drop between List and Tree
</> Source
<!DOCTYPE html>
<html>
<head>
<title>Drag-and-drop between List and Tree</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<link rel="stylesheet" type="text/css" href="../../../codebase/fonts/font_roboto/roboto.css"/>
<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
<script src="../../../codebase/dhtmlx.js"></script>
<link rel="stylesheet" type="text/css" href="../common/demo_style.css"/>
<style type="text/css">
body{ -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none;}
</style>
<script>
dhtmlx.compat("dnd");
var myList, myTree;
function doOnLoad() {
myList = new dhtmlXList({
container:"data_container1",
template:"<span class='dhx_strong'>#name#</span>#address# <br/><span class='dhx_light'>#city#</span>",
drag:true,
type: { height: 80 },
select:true
});
myList.load("../common/list.xml");
myTree = new dhtmlXTreeObject("data_container2","100%","100%",0);
myTree.enableDragAndDrop(true);
myTree.setImagePath("../../../skins/web/imgs/dhxtree_web/");
myTree.load("../../../dhtmlxTree/samples/common/tree.xml");
//drag from tree into the list
myList.attachEvent("onBeforeDrop",function(context){
if (context.from == myTree){
this.add({
name:context.from.getItemText(context.source),
address:"5.0",
city:"DHTMLX team"
}, this.indexById(context.target||this.first()));
context.from.deleteItem(context.source);
return false;
}
return true;
});
//drag from list into the tree
myTree.attachEvent("onDrag",function(sid,tid,tindex, sobj,tobj){
if (sobj.object && sobj.object == myList){
if (tid != 0)
myTree.insertNewNext(tid, sid, myList.get(sid).name );
else
myTree.insertNewChild(tid, sid, myList.get(sid).name );
myList.remove(sid);
return false;
}
return true;
})
}
</script>
</head>
<body onload="doOnLoad();">
<h1>Drag-and-drop between List and Tree</h1>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>
<div id="data_container1" style="border:1px solid #c0c0c0; background-color:white;width:210px;height:400px;"></div>
</td>
<td>
</td>
<td>
<div id="data_container2" style="border:1px solid #c0c0c0; background-color:white;width:400px;height:400px;"></div>
</td>
</tr>
</table>
</body>
</html>
Documentation
Check documentation to learn how to use the components and easily implement them in your applications.