Search code examples
dynatreejquery-dynatree

undo drag and drop of item


I have a full functional dynatree, where data gets load via ajax (database source), now i enabled drag and drop functionality for the tree. When an item gets dropped i do an ajax request to update the database so node data gets updated. But i do several checks in php to see if node is allowed to be placed on it's "new location".

How can i restore the original location of the node if php rejects the new location where the node is dropped? A full tree reload is possible, but i want to avoid that, and just restore the specific item.


Solution

  • Ok , i found a correct way to do this. I just do my ajax request to php but set it to an sync (async false), so the dynatree code will wait for the result. Then i implemented a check around the move function of dynatree:

    $.ajax({
            url: "xxx,
            async: false,
            success: function(data){
                if(data.error == 0){
                    showModalOk(data.message);
                    phpres = true;
                }else
                    phpres = false;
                }
    
            }
        });
    
    if(phpres == true){
        sourceNode.move(node, hitMode);
        node.expand(true);
    }
    

    that way the node only gets moved if it's allowed, so no need to restore the node afterwards