Conditionally Enable/Disable Drag and Drop

4 posts, 0 answers
  1. Preston
    Preston avatar
    3 posts
    Member since:
    Aug 2008

    Posted 15 Mar 2011 Link to this post

    category1
      -  category2
           -  item1
           -  item2
           -  item3
      -  category3
           -  item4
    category4
      -  item5
      -  item6
    category5
      -  category6

    Above is an example of my treeview I'm working with.  I would like to conditionally enable/disable drag and drop functionality per node type. 
    If a node is an item:
      -  it can be dragged into (over) a node that is empty or already has other items in it
      -  it can be dragged next to (above/below) a node that is

    If a node is a category:
      -  it can be dragged into (over) a node as long as that destination node does not have item child nodes

    Is there any way to set this in code when the page loads either through code or attributes?  I have dropping disabled on all item nodes.  I know that I can check the node types on postback, but I'm wanting to not let the user perform the drop initially based on the above criteria, therefore eliminating the unnecessary  postback.  Please help.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Mar 2011 Link to this post

    Hello,


    You could handle this in "OnClientNodeDropping" event of RadTreeView. You cna easily cancel the event using "set_cancel()" method based on your conditions.

    A more clear idea, you will get by going through the documentation.
    OnClientNodeDropping



    Thanks,
    Princy.
  3. Preston
    Preston avatar
    3 posts
    Member since:
    Aug 2008

    Posted 16 Mar 2011 Link to this post

    Does this event fire when dragging a node over another node or only when the user releases the mouse button?  I don't want to cancel the drop, I want to the user to see that they can't drop it there, basically like setting AllowDrop to false, just conditionally.

    Maybe as a future idea for the treeview, have a field (perhaps using the Category field) that tells the node it can only accept, for dropping, nodes of a specified type or types.
  4. Nikolay Tsenkov
    Admin
    Nikolay Tsenkov avatar
    734 posts

    Posted 18 Mar 2011 Link to this post

    Hi Preston,

    This functionality is not that trivial to achieve. You will need to handle at least 2 events and on each drag and drop to traverse the entire TreeView resetting cssClasses.

    My advice is to catch the dropping event and to notify the user post the action.


    Regards,
    Nikolay Tsenkov
    the Telerik team
Back to Top