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

Dragging between two TreeViews

4 Answers 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
AP
Top achievements
Rank 1
Iron
Iron
Veteran
AP asked on 22 May 2015, 09:19 AM

I have an application that needs to support dragging from one TreeView onto another, where items are only copied, not moved.

 I can achieve this using the DragStart event on the destination tree, to prevent any dragging from it.  I can then identify what node has been dragged to the other tree, cancel the operation with PreventDefault, and then append the node manually (and also update the back0end database). What I can't work out how to stop, is nodes from the source tree being dragged onto other nodes in the source tree (which I want as read only).

This is because the drop event always fires from the source tree, and to find out more about the destination node (i.e. the object ID it was created with etc..) requires a call involving the TreeView's name

e.g.:- 

alert($("#Treeview").getKendoTreeView().dataItem(e.dropTarget).id);

 As I have two TreeViews on the page, how do identify which treeview the droptarget is on (or even better, just allow the source tree to allow dragging and not dropping?

 

Thanks

4 Answers, 1 is accepted

Sort by
0
Alex Gyoshev
Telerik team
answered on 26 May 2015, 06:54 AM

Hello AP,

To disable drag&drop within the source TreeView, attach to its drag event and use the e.setStatusClass("k-denied") when the dropTarget is within the source TreeView ($(e.dropTarget).closest("#sourceTreeView").length).

Regards,
Alex Gyoshev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 26 May 2015, 07:42 AM

Alex,

This correctly shows the disallowed icon when an object is dragged within the source tree. However, the drop event still fires when the mouse button is released, causing an error. How do I stop the drop event firing, or check to see if the status is denied?

 

0
Accepted
Alex Gyoshev
Telerik team
answered on 28 May 2015, 05:40 AM

Hello AP,

You can check if the drop operation is valid via the valid flag of the event arguments (e.valid). If the status has been set to "denied", the drag will be invalid, and you can suppress the drop logic. Here is a Dojo snippet that illustrates this.

Regards,
Alex Gyoshev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
AP
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 28 May 2015, 07:42 AM

That's great. I've got it working now.

Thanks

Tags
TreeView
Asked by
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Alex Gyoshev
Telerik team
AP
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or