Dragging between two TreeViews

5 posts, 1 answers
  1. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 22 May 2015 Link to this post

    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

  2. Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 26 May 2015 Link to this post

    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
  3. UI for ASP.NET MVC is VS 2017 Ready
  4. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 26 May 2015 in reply to Alex Gyoshev Link to this post

    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?

     

  5. Answer
    Alex Gyoshev
    Admin
    Alex Gyoshev avatar
    2500 posts

    Posted 28 May 2015 Link to this post

    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
  6. AP
    AP avatar
    187 posts
    Member since:
    Apr 2010

    Posted 28 May 2015 in reply to Alex Gyoshev Link to this post

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

    Thanks

Back to Top
UI for ASP.NET MVC is VS 2017 Ready