简体   繁体   中英

Restrict dropPosotion before and after Kendo UI treeview

When doing drag and drop in Kendo UI TreeView it has 3 positions namely "before", "over" and "after".

http://docs.kendoui.com/api/web/treeview#dragend

Is it possible to restrict the "before" and "after" states and only allow drop "over" functionality.

Note

In my scenario I have 2 trees and I'm dragging element from left tree to the other.

In your kendoTreeView , define drag and drop event handlers as follow:

drag       : function (ev) {
    if (!$(ev.dropTarget).hasClass("k-in k-state-hover")) {
        ev.setStatusClass("k-denied")
    }
},
drop       : function (ev) {
    if (ev.sourceNode === ev.destinationNode) {
        ev.setValid(false);
    }
}

In the drag I check that we are over an element and if not I set that status class to k-denied that it formats the clue as denied but also prevents from dropping it there.

In the drop I just check that I'm not dropping on top of itself preventing a stack overflow.

Running example here: http://jsfiddle.net/OnaBai/mu92b/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM