Drag-and-drop between DataView and Grid
</> Source
<!DOCTYPE html>
<html>
<head>
<title>Drag-and-drop between DataView and Grid</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>
<style type="text/css">
body{ -webkit-user-select:none; -moz-user-select:none; -ms-user-select:none;}
</style>
<script>
dhtmlx.compat("dnd");
var myDataView, myGrid;
function doOnLoad() {
myDataView = new dhtmlXDataView({
container:"data_container1",
type:{
template:"#Package# : #Version#<br/>#Maintainer#",
padding:5,
height:50
},
drag:true,
select:true
});
myDataView.load("../common/data.xml");
myGrid = new dhtmlXGridObject('data_container2');
myGrid.setImagePath("../../../codebase/imgs/");
myGrid.enableDragAndDrop(true);
myGrid.enableAutoWidth(true);
myGrid.load("../../../dhtmlxGrid/samples/common/gridH.xml");
//drag from grid into the dataview
myDataView.attachEvent("onBeforeDrop",function(context){
if (context.from == myGrid){
this.add({
Package:context.from.cells(context.source, 1).getValue(),
Version:context.from.cells(context.source, 2).getValue(),
Maintainer:"not defined"
}, this.indexById(context.target||this.first()));
context.from.deleteRow(context.source);
return false;
}
return true;
});
//drag from dataview into the grid
myGrid.attachEvent("onDrag",function(sid,tid,sobj,tobj){
if (sobj.object && sobj.object == myDataView){
var d = myDataView.get(sid);
var index = myGrid.getRowIndex(tid);
myGrid.addRow(myGrid.uid(), [sid, d.Package, d.Version], index);
myDataView.remove(sid);
return false;
}
return true;
})
}
</script>
</head>
<body onload="doOnLoad();">
<h1>Drag-and-drop between DataView and Grid</h1>
<table border="0" cellspacing="5" cellpadding="5">
<tr>
<td>
<div id="data_container1" style="border:1px solid #c0c0c0; background-color:white;width:240px;height:396px;"></div>
</td>
<td>
</td>
<td>
<div id="data_container2" style="width:600px;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.