This is a migrated thread and some comments may be shown as answers.

list of children after drop

3 Answers 176 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
DDarko
Top achievements
Rank 1
DDarko asked on 23 Nov 2011, 05:18 PM
This is obvious:
var treeview = $("#treeview").kendoTreeView({
dragAndDrop: true,
drop: function(e){
...
}
});

But I have no idea how to get the "text" of the parent node, in which item is dropped.
And how to get a list / array of children for that parent.
eg. ["item 1.1", "item 1.2", "item 1.3"]

Is there a method for node like children() ?

3 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 25 Nov 2011, 09:17 AM
Hi Ddarko,

Assuming that you get the TreeView object like so:
var kendoTreeView = $("#TreeView").data("kendoTreeView"),
    parent = item.parent().closest(".k-item");


> how to get the "text" of the parent node
kendoTreeView.text(parent);

> how to get a list / array of children for that parent
parent.find("> .k-group > .k-item").map(function() {
    return kendoTreeView.text(this);
});


We don't have a kendoTreeView.children(parent) method yet, but we'll consider adding one.

Best wishes,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
DDarko
Top achievements
Rank 1
answered on 08 Dec 2011, 11:53 AM
First part:
How to get the parent node, in which item is dropped ?


You used something like this:
var parent = item.parent().closest(".k-item");


But what is the "item" and how to get it from the "e"?






I did it as follows:


<ul id="treeview">
    <li node-id="/a">Item 1
        <ul>
            <li node-id="/a/c">Item 1.1</li>
            <li node-id="/a/d">Item 1.2</li>
        </ul>
    </li>
    <li node-id="/b">Item 2</li>
</ul>


var treeview = $("#treeview").kendoTreeView({
animation:false,
dragAndDrop:true,
drop: function(e){

if (e.dropPosition == 'over') {
var parent_id = $(e.dropTarget).parent().parent().attr('node-id');

} else {
var parent_id = $(e.dropTarget).parent().parent().parent().parent().attr('node-id');
if (!parent_id) parent_id = ''; // root node have no ID
}

console.log(parent_id);

}
}).data("kendoTreeView");


But maybe it can be done better?
0
Alex Gyoshev
Telerik team
answered on 08 Dec 2011, 03:31 PM

The dropLocation is relative to e.destinationNode. You can refer to the events documentation in the online demos.

Greetings,
Alex Gyoshev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
TreeView
Asked by
DDarko
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
DDarko
Top achievements
Rank 1
Share this question
or