Drag and drop between list and treetable

Hello,

I have a treetable with data :

var listTable =[
{
id:“1”, name:“list1”, open:0, data:[
{“id”:“1.1”,“name”:“Toto3”, “priority”: “1”},
{“id”:“2.1”,“name”:“Toto4”, “priority”: “2”},
{“id”:“3.1”,“name”:“Toto17”, “priority”: “8”},
]
},
{
id:“2”, name:“list2”, data:[
{“id”:“2.1”,“name”:“Toto19”,“type”:“SMS”, “priority”: “1”},
{“id”:“2.3”,“name”:“Toto20”,“type”:“SMS”, “priority”: “3”},
]
},
{
id:“3”, name:“list3”
}
];

And I have a list with data :
{“id”:“1”,“name”:“Titi1”,“priority”: “1”},
{“id”:“2”,“name”:“Toto2”,“priority”: “2”},
{“id”:“3”,“name”:“Toto3”, “priority”: “3”},

So I want to use drag and drop (copy , not remove in list view) to add an entry list in second level of treetable (with others) when the entry list is drop on the first level of treetable (list1 or list2 or list3)

I tryied :

$$(“listsTreeTable”).attachEvent(“onBeforeDrop”, function (context, ne){
if (context.parent != 0) return false;
for (var i=0; i < context.source.length; i++) {
context.from.copy(context.source[i],context.start, this, context.parent+"."+context.source);
}
$$(“listsTreeTable”).refresh();
return false;
});

But the problem is that list entry is alone on first level in treestore …
Any Ideas ?

Thank you

Hello,

The second parameter of copy() method is a position of the item in a branch whether it is dropped to. The parent id should be set in details (the 4th parameter):

http://docs.webix.com/api__treedatamove_copy.html

For example as in:

c.from.copy(c.source[i], c.index, this, {parent:c.target});

Thanks for the response, it doesn’t work for the moment , the element is placed into the treetable, but isn’t a branch of parent’s element with this method :wink:

Hi, please check the next snippet

http://webix.com/snippet/29fc6fcd

If you drop item from list on some child item in the treetable, new item will be added into the related branch.