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

Conditionally Enable/Disable Drag and Drop

7 Answers 104 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
Preston
Top achievements
Rank 1
Preston asked on 15 Mar 2011, 11:16 PM
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.

7 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 16 Mar 2011, 10:51 AM
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.
0
Preston
Top achievements
Rank 1
answered on 16 Mar 2011, 02:40 PM
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.
0
Nikolay Tsenkov
Telerik team
answered on 18 Mar 2011, 05:04 PM
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
0
Erik
Top achievements
Rank 1
answered on 19 Nov 2020, 04:30 PM

 

 

Cant you just do something like this using the asp.net razor syntax?

            @{ 
                var dnd = false;

                @(Html                                              
                                .Kendo()                                        
                                .TreeView()                                     
                                .Name("ktreeview")                              
                                .TemplateId("treeview-template")                
                                .DataTextField("Name")                          
                                .DataSource(dataSource => dataSource            
                                    .Read(read => read                          
                                        .Action("Read_TreeViewData", "Index")   
                                    )
                                    .Custom()
                                )

                                .DragAndDrop(@dnd)

                                .Deferred(true)  
                )
            }

0
Erik
Top achievements
Rank 1
answered on 19 Nov 2020, 04:32 PM

Sorry. I read over/did not grasp that it was per node type.

 

0
Preston
Top achievements
Rank 1
answered on 19 Nov 2020, 07:17 PM
Dude! This post was from March 2011. Thanks for the help, but I've moved on, lol.
0
Erik
Top achievements
Rank 1
answered on 19 Nov 2020, 07:43 PM
Ok...Bill and Ted mode it is...

But Dude! Mind blown! The history is all about the future. Posts live forever dude...so now it's less about you and your most excellent skills and more about the noobs who are just trying to catch this wave now. Scale back and take a chill. We can pay it forward, and we'll all be excellent together.
Tags
TreeView
Asked by
Preston
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Preston
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Erik
Top achievements
Rank 1
Share this question
or