list of children after drop

4 posts, 0 answers
  1. DDarko
    DDarko avatar
    17 posts
    Member since:
    Oct 2011

    Posted 23 Nov 2011 Link to this post

    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() ?

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 25 Nov 2011 Link to this post

    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!
  3. DDarko
    DDarko avatar
    17 posts
    Member since:
    Oct 2011

    Posted 08 Dec 2011 Link to this post

    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?
  4. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2527 posts

    Posted 08 Dec 2011 Link to this post

    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!
Back to Top