Prevent the Dragging of Nodes to Deep TreeView Levels
Environment
Product | Progress® Kendo UI® TreeView for jQuery |
Operating System | Windows 10 64bit |
Visual Studio Version | Visual Studio 2017 |
Preferred Language | JavaScript |
Description
How can I prevent the nodes from being dragged to a deeper tree level in the Kendo UI for jQuery TreeView?
Solution
The following example demonstrates how to handle the drag
event to achieve this behavior.
<div id="treeview"></div>
<script>
$("#treeview").kendoTreeView({
dragAndDrop: true,
dataSource: [
{ text: "foo", expanded: true, items: [
{ text: "bar", expanded: true, items: [
{ text: "baz", expanded: true, items: [
{ text: "qux" },
{ text: "cat" },
{ text: "dog" }
] }
] }
] }
]
});
var treeview = $("#treeview").data("kendoTreeView");
treeview.bind("drag", function(e) {
// If the current status is "add", then the node will be appended.
if (e.statusClass == "add") {
var destination = this.dataItem(e.dropTarget);
// If the (zero-based) destination level is 3,
// allowing the operation will result in a 5-level tree..
if (destination.level() == 3) {
// Deny the operation.
e.setStatusClass("k-denied");
}
}
});
</script>