Drag Only Parents from Tree to Grid

Hello,

i’ve searched hours for a solution of this problem, so i hope you can help me :slight_smile:

The problem is, i have a tree and i drag a parent node to a grid and dont want that the child elements also be dropped into the grid, so i want only the parent node, not the childs…

The Knowledgebase say some solutions, but nothing work, i make the onDrag event on the Grid, but this hasnt an additional parameter before id, so i can store the parentId and returning an false if the actual id is a child of the beforeId, this was the best solution idea i’ve found…

So i hope you understand my problem and can help me.

Thanks
Michael

Hello,

the easiest way is to block drag-n-drop for tree item and manually add row to grid:

grid.attachEvent(“onDrag”,function(sId,tId,sObj,tObj){
if(sObj==tree){
grid.addRow(sId,[tree.getItemText(sId)],this.getRowIndex(tId)+1);
tree.deleteItem(sId);
return false;
}
return true;
})

Hello,

your solution doesnt works. It deletes entries from the tree, i want no childs of an dragged elment in grid…

But i’ve found a solution:

	var childs;
	var parentId = null;

	grid.treeToGridElement = function(treeObj, treeNodeId, gridRowId) {
		if(treeObj.getParentId(treeNodeId)==parentId){
			childs.push(treeNodeId);
		}
		return [treeNodeId, treeObj.getItemText(treeNodeId)];
    }

	grid.attachEvent('onDrop',function(){
		for(i=0;i<childs.length;i++){
			grid.deleteRow(childs[i]);
		}
		return true;
	});

	grid.attachEvent("onDrag", function(sId,tId,sObj,tObj) {
		parentId = sId;
		childs = new Array();
		if(grid.doesRowExist(sId)){
			return false;
		}
		return true;
	});

Hello

You can exclude deleteItem call from the provides approach if you want to copy nodes:

grid.attachEvent(“onDrag”,function(sId,tId,sObj,tObj){
if(sObj==tree){
grid.addRow(sId,[tree.getItemText(sId)],this.getRowIndex(tId)+1);
return false;
}
return true;
})