Remove item from tree after drag-and-drop in dhtmlxScheduler

I have the free version of the Tree and the Scheduler. Drag and drop is enabled, I can drag tree items to the scheduler, and it does some things.

What I like to do is to remove the dragged and dropped item from the tree when I submit the form from the scheduler.

Can anyone help me here? I have tried the onDrop() event, but no response.

PS: The removing should only happen if I click “Save” in the form on the scheduler, if I click “Cancel”, the item should stay in the tree.

Hello,

scheduler.attachEvent("onExternalDragIn", function(id, source, e){
    var tree_item_id = tree._dragged[0].id; // getting tree item id
    scheduler._dragged_tree_item = tree_item_id; // setting custom flag with tree item id when item was dragged in
    var label = tree.getItemText(tree_item_id);
    var ev = scheduler.getEvent(id);
    ev.text = label;
    return true;
});

scheduler.attachEvent("onEventSave", function(id, data, is_new_event) {
    if(scheduler._dragged_tree_item)
        tree.deleteItem(scheduler._dragged_tree_item); // if flag is set then event was created using dnd and we need to delete item from the tree
    return true;
});

scheduler.attachEvent("onAfterLightbox", function () {
    scheduler._dragged_tree_item = false; // resetting flag after lightbox was closed
});

Best regards,
Ilya

Thank you, this helps a lot. Now I’m trying the next thing. Remove from the node, and add to another node (or move basically). The tree is as follows:

Tickets

  • New
  • Planned
  • Closed

When I move drag and drop, the items should move to the node ‘planned’.

I use the following code:

tree.moveItem(scheduler._dragged_tree_item, 'item_child', tckCatPln);

The variable tckCatPln contains the ID of the planned node (ticket_7)

But this doesn’t quite work.

Make sure that item with id scheduler._dragged_tree_item is added to the tree before moveItem is called. moveItem can be applied only to tree nodes.

I don’t really get what you mean. The item is already in the tree, but instead of deleting it, I would like to move it to another node (which also exists).

But this doesn’t quite work.

What did you mean ? Locally moveItem works correctly. You may attach the sample that reproduces the problem.

Hello, I am also trying to remove an item from the tree. I tried copying and pasting your code without success. It seems like onEventSave isn’t working for me. I even tried:

scheduler.attachEvent("onEventSave", function(id, data, is_new_event) {
    alert("Hello");
    return true;
});

And I do not get the alert when I save, whether it is from a drag and drop or from a newly created event. I’m sure I am missing something…any ideas?

I figured it out. The onEventSave only works when you open the lightbox and save it. I changed my code to onEventAdded and it works great!