Limit node reordering depth

2 posts, 0 answers
  1. Blagojce
    Blagojce avatar
    1 posts
    Member since:
    Oct 2011

    Posted 21 Oct 2011 Link to this post

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

    Posted 21 Oct 2011 Link to this post

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