Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop node drop event with primeng p-tree component

I am using primeng p-tree component and i would like to forbid some node type to be drop inside another node type.

for exemple i have node with type folder and another node with type file and i only want that node of type file move inside a node of type folder. I want to forbid moving folder node inside another folder node. (and other rules

<p-tree [value]="filesTree7" draggableNodes="true" droppableNodes="true" dragdropScope="files" selectionMode="single" [(selection)]="selectedFile2" [contextMenu]="cm" (contextmenu)="onContextMenu($event)"
          (onNodeDrop)="onNodeDrop($event)"></p-tree> 

I tried to stop propagation of the drop like this :

onNodeDrop(event) {
    console.log("onNodeDrop");
    event.originalEvent.stopPropagation();
    event.originalEvent.preventDefault();
    return;
}

but it is not working.

when i have a look to primeng code here : primeng tree component code source it seems that onNodeDrop event is emit too late.

Do you have any ideas how i can implement what i need ?

like image 631
toregua Avatar asked Jun 20 '26 22:06

toregua


1 Answers

If you want that a single node isn't droppable or draggable you must set params draggable/droppable in array:

{
    "label": "Note e Commenti",
    "icon": "fa-file-word-o",
    "draggable":false,
    "droppable":false,
    "data": {
        "id": 1,
        "nome": "Note e Commenti",
        "testo": "Note e Commenti",
        "idCategoria": 2,
        "idTipologia": 1
    }
},
like image 151
filippo mazzei Avatar answered Jun 23 '26 03:06

filippo mazzei