I have 2 trees and need to drag node to node from one tree to another?
But I can’t do this.But when I drag node to folder it’s ok.
See canDropOnLeaves.
Ok I’ve tried but nothing is happening
But it’s only says:
This item already contains a child item with that name
Because can’t drag on node. But when I drag node to folder It’s ok.
My trees:
isc.PartsTreeGrid.create({
ID:"myTree1",
autoFetchData: true,
canEdit: true,
canReorderRecords: true,
canAcceptDroppedRecords: true,
canDragRecordsOut: true,
canDropOnLeaves:true,
dragDataAction: "move",
nodeIcon:"icons/16/person.png",
showDropIcons:false,
showFilterEditor: true,
closedIconSuffix:"",
editByCell: true,
editEvent: "click",
canFilter:true,
folderDrop : function (dragRecords, dropFolder) {
var id = dropFolder.id;
var node = myTree1.getSelectedRecord();
myTree1.fetchData({dragRecord : dragRecords, dragOn:id});
},
data: isc.Tree.create({
ID:"partsTree1",
modelType: "parent",
rootValue: 0,
nameProperty: "name",
idField: "id",
parentIdField: "parentId",
autoFetchData: true,
dataSource: "mappingSpringDMI"
}),
fields: [
{name: "name", title:"Legal Name", canEdit:false, canFilter:true, width:200},
{name: "id", title:"Address", canEdit:false, canFilter:false}
]
}),
isc.VStack.create({width:32, height:74, layoutAlign:"center", membersMargin:10, members:[
isc.Img.create({src:"icons/32/arrow_right.png", width:32, height:32,
click:"myTree2.transferSelectedData(myTree1)"
}),
isc.Img.create({src:"icons/32/arrow_left.png", width:32, height:32,
click:"myTree1.transferSelectedData(myTree2)"
})
]}),
isc.PartsTreeGrid.create({
ID:"myTree2",
left:250,
autoFetchData: true,
canEdit: true,
canReorderRecords: true,
canAcceptDroppedRecords: true,
canDragRecordsOut: true,
canDropOnLeaves:true,
dragDataAction: "move",
nodeIcon:"icons/16/person.png",
showDropIcons:false,
showFilterEditor: true,
closedIconSuffix:"",
editByCell: true,
editEvent: "click",
canFilter:true,
folderDrop : function (dragRecords, dropFolder) {
var id = dropFolder.id;
myTree2.fetchData({dragRecord : dragRecords, dragOn : id});
},
data: isc.Tree.create({
ID:"partsTree2",
modelType: "parent",
rootValue: 0,
nameProperty: "name",
idField: "id",
parentIdField: "parentId",
autoFetchData: true,
dataSource: "mappingSpringDMI"
}),
fields: [
{name: "name", title:"Name", canEdit:false, canFilter:true, width:200},
{name: "id", title:"Address", canEdit:false, canFilter:false}
]
})
]})
As far as you recommended I’ve set property:
canDropOnLeaves:true
But it can’t do be drag leave on leaves(node to node)
Hi dareha,
CanDropOnLeaves should allow you to drop on either Folder or Node (leaf) elements within the grid. However it doesn’t allow dragging and dropping a node into its own parent by default, since the drop-target folder would match the source folder of the node, implying you’re not actually modifying the tree data.
If you do want support for drag/drop of nodes within their parent folder (rather than only allowing reparenting of nodes), you should set ‘canReorderRecords’ to true for the grid.
Let us know if this doesn’t work for you
Thanks
Isomorphic Software
It doesn’t working for a leaf but ok for a folder.
What I really need:
myTree1 myTree2
----------------- -----------------
NODE1 NODE1
NODE2 NODE2
NODE3 NODE3
FOLDER4 FOLDER4
NODE5 NODE5
NODE6 NODE6
FOLDER7 FOLDER7
NODE8 NODE8
NODE9 NODE9
myTree2 the copy of myTree2
I need map NODE1 to NODE2 to got the following:
myTree1 myTree2
----------------- -----------------
FOLDER2 FOLDER2
NODE1 NODE1
NODE3 NODE3
FOLDER4 FOLDER4
NODE5 NODE5
NODE6 NODE6
FOLDER7 FOLDER7
NODE8 NODE8
NODE9 NODE9
The code of my tree is higher.
In Plain English
we have two trees like in the example here
http://www.smartclient.com/#_Trees_Interaction_Drag.nodes
we want to be able to drag a leaf from one tree onto a leaf from another tree and for that leaf to then become a folder containing the leaf from the first tree.
We thought it might be possible if we made all of the leaves folders but when we do this we get some kind of duplication issue when the user clicks on an empty folder.
Can you help?
If you are getting that duplication error when dragging from one TreeGrid to another, then the problem is that you have given both TreeGrids the same Tree or the same set of data. If you want the Trees to be indentical initially, use isc.clone() on the data you pass to each code.
However this technique has nothing to do with the code you’ve shown, which in turn has nothing to do with your stated requirements… the code you’ve shown overrides the normal folderDrop() behavior in order to fetch new data from the server and does not attempt to modify the tree structure at all.
Thanks for your help
We have added clone operation to the our tree. So now we have no “this item already contains such name” warning.
But we still cannot drag&drop to leaf node
Function folderDrop receives wrong value of the folder parameter(The folder being dropped on). Seems that we get the root folder or parent folder of the target leaf node
Please, see tree creation procedure above in our post
Tree parameters are:
autoFetchData: true,
canEdit: true,
canReorderRecords: true,
canReparentNodes:true,
canDrop:true,
canAcceptDroppedRecords: true,
canDragRecordsOut: true,
canDropOnLeaves:true,
dragDataAction: "move",
nodeIcon:"icons/16/person.png",
showDropIcons:false,
showFilterEditor: true,
closedIconSuffix:"",
editByCell: true,
editEvent: "click",
canFilter:true,
Regardless of whether you are dropping on a leaf or folder, folderDrop() will pass the containing folder as the “dropFolder” parameter, and the leaf node actually dropped on is accessible as “this.data.getChildren(dropFolder)[index]”.
Thanks isomorphic for your great help. It’s works
Hi,
I’m getting a similar issue to this (7.0RC1), however, no matter where I drop, the index parameter to folderDrop() is always null.
Here is my test code, which is just two trees with dummy data.
isc.VLayout.create({
members: [
isc.TreeGrid.create({
height: 200, width: 600,
nodeIcon: "icons/16/folder_document.png", folderIcon: "icons/16/folder_document.png",
showOpenIcons: false, showDropIcons: false, closedIconSuffix:"",
canDragRecordsOut: true, canAcceptDroppedRecords: true, canDropOnLeaves: true,
data: isc.Tree.create({
modelType: "parent",
nameProperty: "Name",
idField: "EmployeeId",
parentIdField: "ReportsTo",
data: [
{EmployeeId:"4", ReportsTo:"1", Name:"Charles Madigen"},
{EmployeeId:"188", ReportsTo:"4", Name:"Rogine Leger"},
{EmployeeId:"189", ReportsTo:"4", Name:"Gene Porter"},
{EmployeeId:"265", ReportsTo:"189", Name:"Olivier Doucet"},
{EmployeeId:"264", ReportsTo:"189", Name:"Cheryl Pearson"}
]
}),
fields: [
{name: "Name", treeField:true}
],
folderDrop : function(nodes, folder, index, sourceWidget) {
isc.Log.logInfo("Dropped on:" + folder.Name + ", index: " + index);
}
}),
isc.TreeGrid.create({
height: 200, width: 600,
nodeIcon: "icons/16/folder_document.png", folderIcon: "icons/16/folder_document.png",
showOpenIcons: false, showDropIcons: false, closedIconSuffix:"",
canDragRecordsOut: true, canAcceptDroppedRecords: true, canDropOnLeaves: true,
data: isc.Tree.create({
modelType: "parent",
nameProperty: "Name",
idField: "EmployeeId",
parentIdField: "ReportsTo",
data: [
{EmployeeId:"3", ReportsTo:"1", Name:"A"},
{EmployeeId:"1848", ReportsTo:"3", Name:"B"},
{EmployeeId:"1829", ReportsTo:"3", Name:"C"},
{EmployeeId:"2625", ReportsTo:"1829", Name:"D"},
{EmployeeId:"2624", ReportsTo:"1829", Name:"E"}
]
}),
fields: [
{name: "Name", treeField:true}
],
folderDrop : function(nodes, folder, index, sourceWidget) {
isc.Log.logInfo("Dropped on:" + folder.Name + ", index: " + index);
}
})
]
});
So when dropping from either tree to the other’s nodes (leaf or folder), my log output is something like
17:43:54.586:MUP0:INFO:Log:Dropped on:C, index: null
...
17:45:11.794:MUP0:INFO:Log:Dropped on:Gene Porter, index: null
so I can’t see a way to determine the node (leaf) that was actually dropped on.
Is this expected behaviour? If so, what mechanism is there for me to determine the node that was dropped on? Thanks for your help,
Colin
Set canReorderRecords:true to enable dropping at specific positions (including a drop line showing the drop position during dragging).
Thanks for the info - that gets the index value set.
Is there an easy way to avoid showing the line? I’m not trying to insert a record into the TreeGrid, but drop a record ‘on’ a TreeNode. My use-case is a Tag tree, and you tag other records by dropping them on a tag in the tag tree.
I could also see a use case for dropping on (rather than between) leaves when you want to insert a node as the child of a leaf.
It seems to me that at some point, SmartClient must be aware that the drop action is occurring on a leaf, but chooses to translate that information before making it available via an API.
Feels like I am still missing something about how this works. Thanks for your help,
Colin
For that use case we’d probably recommend against canDropOnLeaves. It’s simpler to just have all nodes be folders - you can use whatever icons you like, and you can avoid showing an opener control by assuring they have no children. So long as you override drop or folderDrop and don’t call Super(), children will not be added by the drag and drop interaction.
Ah - unfortunately, I’m using the loadOnDemand, and using the isFolderProperty to indicate that there are no children.
I’m pretty sure I have come to a solution though - just override drop()
drop : function() {
var dropRow = this.getEventRow();
var dropFolder = this.getDropFolder();
var dropRecord = null;
if(dropRow >= 0) dropRecord = this.getRecord(dropRow);
var draggedRecords = isc.Event.getDragTarget().getDragData();
// handle drop event
}
For my use case, I just need the dropRecord, and the draggedRecords - do you see any issues with this approach? Thanks,
Colin
Even with loadOnDemand, you can use the isFolderProperty to mark nodes as folders, but also provide an explicit, empty children array to indicate that there are no children to load.
Ok. The xml structure I am dealing with doesn’t support the children as a contained structure. When I retrieve a record from the server, it comes with a field that indicates if it has children (my isFolderProperty).
I guess I could observe this field in a customised datasource, and if it is a leaf, change the field to indicate folder, and manipulate the data to add the empty array, and then manipulate everything back again before sending to the server. Sounds like an awful lot of work to know that I dropped something on a leaf. To be fair, the record is a leaf, not a folder - this doesn’t feel like the right solution.
I seem to have everything working ok, though, using the solution from the previous post. It seems much more robust than trying to manipulate the data structures to trick smartclient into thinking that leaves are folders.
Do you see any problems with the approach of overriding drop() instead? Thanks,
Colin
Overriding drop() is fine (you’re going to need to whether it’s a folder or not, to prevent children being added) our impression was that you still wanted drop animations to behave as though the node were folders. If not, you’re all set.
setCanDropOnLeaves
Hi,
I’ve also been trying to play with the drag and drop, and as the original poster (dareha), I can’t drop on leaves even though I’ve set the property on my trees. What I’ve seen is that those who complain about this, use (just as I do) the PARENT TreeModelType (and not CHILDREN as in the showcase). So I was wondering if that would be the reason why we can’t drop on leaves.
My workaround is to set all nodes as folders, but this shows a ‘+’ icon in front of the node to indicate that we can open it, and I don’t want that. You mentioned the fact that we can change this [you can avoid showing an opener control by assuring they have no children], how does it work if we are using the PARENT model?
Another quick question:
Can we set, when creating/adding a node, which leaf icon and folder icon to use, so that we don’t have to manually set our custom icon each time the node is moved (using the events). Something like:
setLeafIcon(String icon)
setFolderIcon(String icon) and SmartGWT would automatically use this or the default if null…? I could propose this in the Google Code Issues if you want.
Thank you for your work and quick answers!
Leaves and Folders
Hello,
I’ve now understood that setting canDropOnLeaves to true won’t allow to actually transform a leaf into a folder and adding the new node as its new child, but just throwing the event according to it.
So I’ve seen in a thread that we have to set the nodes as Folders (setIsFolder(true)), and use the setIsFolderProperty(“is_folder”) to custom the fact that it has children or not, thus showing the ‘+’ icon or not. But if I do: setAttribute(“is_folder”, false), then the node is considered as a leaf, and we can’t drop children to it…
How am I supposed to configure the tree so that its nodes can accept new children on the fly (just drag n drop on it), but without showing the little ‘+’ icon when no children are left…
Just to know, because it may have an effect, set load on demand is false.
Thank you