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

Prevent Drag and Drop between Two Trees if node exists

3 Answers 200 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
axwack
Top achievements
Rank 1
axwack asked on 15 Feb 2016, 01:23 PM

I believe this function can work using k-denied but still not very good with the JS for the tool suite. I have two treeviews. I'm working on a screen where once a treeview is persisted to the DB, a user could go back and update it with new nodes, a reordering of nodes or deleting the nodes.

How can I validate that if a node is dragged from the left tree to the right tree, that if the ID (identified by ext_model_id) exists, don't drop on the tree? How can I see if the node is even there? Do I use the data-uid?

 Help would be appreciated.

3 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 18 Feb 2016, 09:23 AM
Hi Vincent,

You can consider using the dataSource.get(id) and treeView.findByUid() methods to check whether a node with the sought id exists in the target data source. Example:

var treeview = $("#treeview").data("kendoTreeView");
var barDataItem = treeview.dataSource.get(2);
var barElement = treeview.findByUid(barDataItem.uid);


Regards,
Genady Sergeev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
0
axwack
Top achievements
Rank 1
answered on 18 Feb 2016, 11:59 AM
That may not work because the hid is different between the two nodes. The left side is generated by the stored adjacency list in the db and the right side is as well. The code makes an Ajax call to get nodes. In your second is there a way to find out which level or row the node is on? I ended up solving by looking at the text and comparing.
0
Alex Gyoshev
Telerik team
answered on 22 Feb 2016, 03:25 PM

Hello axwack,

Indeed, the uid may change, between reloads or if only the data is inserted when moving the item. If you have a way of identifying nodes by ID, you can get the ID of the node that is being dragged, and see if the same ID exists in the target treeview. See this Dojo snippet for a demo.

Regards,
Alex Gyoshev
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
TreeView
Asked by
axwack
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
axwack
Top achievements
Rank 1
Alex Gyoshev
Telerik team
Share this question
or