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

Limit node reordering depth

1 Answer 148 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Blagojce
Top achievements
Rank 1
Blagojce asked on 21 Oct 2011, 09:37 AM
Hi,

Is it possible that I can limit the depth of the subnodes added when dragging a node? For example not to be able to create second level nodes, just root nodes and children to them.

Thanks,
Blagojce

1 Answer, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 21 Oct 2011, 11:49 AM
Hi Blagojce,

Attach an event handler to the drag event and use the setStatusClass to set the class to k-denied, like so:

$("#treeview-left").data("kendoTreeView").bind("drag", function(e) {
    if (e.statusClass != "add") { // the operation is adding, not reordering
        return;
    }

    var isValid = true;
    // place any custom validation regarding the reordering, using e.sourceNode and e.dropTarget here
    if (!isValid) {
        e.setStatusClass("k-denied"); // show the "denied" status, that does not allow node drops
    }
});


This will provide an intuitive drag clue (showing that the node cannot be dropped there) and an animation when the node is incorrectly dropped.

All the best,
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
Blagojce
Top achievements
Rank 1
Answers by
Alex Gyoshev
Telerik team
Share this question
or