DHTML Tree + Grid sample

Implementing both dhtmlxTree & dhtmlxGrid in your application you can improve flexibility and functionality of its user interface by interacting between these components.
Drag-and-drop elements from the tree into the grid and vice versa.

    
</> Source
<!DOCTYPE html>
<!--pro-->
<html>
<head>
	<title>DHTML Tree + Grid sample</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"/>
	<script>
		var myGrid, myTree;
		function doOnLoad(){
			myGrid = new dhtmlXGridObject('gridbox');
			myTree = new dhtmlXTreeObject("treeboxbox_tree","100%","100%",0);
			setTimeout("buildTree()",10);
			setTimeout("buildGrid()",11);
		}
		function buildTree(){
			myTree.setImagePath("../../../skins/web/imgs/dhxtree_web/");
			myTree.enableDragAndDrop(true);
			myTree.load("../common/tree.xml");
			myTree.setSerializationLevel(true,true);
		}
		function buildGrid(){
			//set grid parameters
			myGrid.selMultiRows = true;
			myGrid.setImagePath("../../../codebase/imgs/");
			myGrid.setHeader("Sales,Book Title,Author,Price");
			myGrid.setInitWidths("80,150,120,*");
			myGrid.setColAlign("right,left,left,right");
			myGrid.setColTypes("dyn,ed,ed,price");
			myGrid.setColSorting("int,str,str,int");
			myGrid.enableDragAndDrop(true);
			//start grid
			myGrid.init();
			myGrid.load("../common/grid.xml");
			myGrid.treeToGridElement = function(treeObj,treeNodeId,gridRowId){
				return [0,treeObj.getItemText(treeNodeId)];
			};
			//redefine grid-to-tree drop element
			myGrid.gridToTreeElement = function(treeObj,treeNodeId,gridRowId){
				return this.cells(gridRowId,1).getValue()+"/"+this.cells(gridRowId,2).getValue();
			};
			myGrid.attachEvent("onGridReconstructed",function(){this.setSizes()});
			myGrid.rowToDragElement = function (id){
				if(this.cells(id,2).getValue()!="")
					return this.cells(id,2).getValue()+"/"+this.cells(id,1).getValue();
				return this.cells(id,1).getValue();
			}
		}
	</script>
</head>
<body onLoad="doOnLoad()">
	<h1>Tree + Grid</h1>
	<p>Implementing both dhtmlxTree & dhtmlxGrid in your application you can improve flexibility and functionality of its user interface by interacting between these components.<br>
		Drag-and-drop elements from the tree into the grid and vice versa. </p>
	<table>
		<tr>
			<td valign="top">
				<div id="treeboxbox_tree" class="tree_demo_samples"></div>
			</td>
			<td valign="top">&nbsp;&nbsp;&nbsp;&nbsp;
			</td>
			<td valign="top">
				<div id="gridbox" width="450px" height="300px" style="background-color:white;overflow:hidden"></div>
			</td>
		</tr>
	</table>
</body>
</html>

Documentation

Check documentation to learn how to use the components and easily implement them in your applications.