dnd - limit dragging or dropping to certain nodes

2,440 views
Skip to first unread message

kro

unread,
Jun 6, 2014, 10:41:34 AM6/6/14
to jst...@googlegroups.com
hi

using jstree 3 i would like to limit the depth of my tree disallowing dropping on certain nodes.

Here is my (simplified) code :

$('#tree').jstree({
   
"plugins":["dnd"],
   
"core":{
       
"check_callback":true
   
},
   
"dnd":{
       
"copy":false
   
}
}).on("move_node.jstree", function(node,nodes){
    console
.log("node : "+nodes.node.id);
    console
.log("parent : "+nodes.node.parent);
    console
.log("position : "+nodes.position);
});

i found documentation about this for older version but not jstree 3

i tried a classic return false; on certain condition on the move_node function - it doesn't change anything.
so i guess my question would simply be : how can i disable move_node on certain condition - the best way would be not allowing dragging on certain nodes (i.e. not displaying the triangle in front of them - and a red cross instead of the green mark) of course this nodes would still be draggable and act like any other nodes.

but i wish some nodes would not be draggable as well...

if it's not yet implemented i guess the best way to do it would be with data-jstree : 
<li data-jstree='{ "draggable":false }'>
or
<li data-jstree='{ "droppable":false }'>



thanks for any help

Marc R

unread,
Dec 8, 2014, 10:48:41 AM12/8/14
to jst...@googlegroups.com
What if we want to stop certain nodes from allow drops (i.e. I want the red X over a node if a certain condition arrises... i.e shouldn't be allowed childred)?

Thanks,

On Friday, 6 June 2014 15:36:39 UTC-4, Ivan Bozhanov wrote:
Use the types plugin - it has depth control and will automatically show OK / NOT OK icons and disallow drag'n'drop where the depth would be exceeded. As for controlling which nodes are draggable - use the dnd.is_draggable setting. Both are described on jstree.com - plugins & API sections.
Tell me if you need more help.

Best regards,
Ivan

Ivan Bozhanov

unread,
Dec 9, 2014, 1:27:34 AM12/9/14
to jst...@googlegroups.com
I already answered in your topic - for custom comditions - use check_callback

Best regards,
Ivan

Ivan Bozhanov

unread,
Jun 6, 2014, 3:36:39 PM6/6/14
to jst...@googlegroups.com
Use the types plugin - it has depth control and will automatically show OK / NOT OK icons and disallow drag'n'drop where the depth would be exceeded. As for controlling which nodes are draggable - use the dnd.is_draggable setting. Both are described on jstree.com - plugins & API sections.
Tell me if you need more help.

Best regards,
Ivan

06 юни 2014, петък, 17:41:34 UTC+3, kro написа:

Aitor Ramos Sasselli

unread,
May 10, 2017, 8:29:50 AM5/10/17
to jsTree
But with "check_callback" function, you're still not able to show red cross when a condition is rised. f.e. If I need to prevent drops from a certain type of node to another, green tick is still showing. How can I change it?

Thanks in advance
Reply all
Reply to author
Forward
0 new messages