High-Performance UI Component Library for Enterprise Applications Forums Gantt How can I implement undo and redo for task edits in Smart Gantt while keeping se

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #113612
    natejacobson
    Participant

    Hi everyone, I am working on a scheduling screen for support teams with Gantt. I am currently trying to solve this: How can I implement undo and redo for task edits in Smart Gantt while keeping server data consistent? So far, I can reproduce it consistently in a small demo, but the UI behaves inconsistently after data updates. What approach would you recommend here?

    #113631
    admin
    Keymaster

    Hi,

    The cleanest way to implement undo/redo for Smart Gantt task edits is to treat every edit as a command with a before/after state, rather than trying to restore the entire chart state.

    Keep a history stack containing the changed task data:

    – Before a task edit starts, store the original task state.
    – After the edit completes, store the new state.
    – Undo applies the old state.
    – Redo applies the new state.
    – Keep server persistence separate: when an undo/redo action changes a task, send the resulting task state back to the API so the backend stays synchronized.

    A typical structure looks like:

    const undoStack = [];
    const redoStack = [];
    
    function saveTaskChange(oldTask, newTask) {
        undoStack.push({
            oldValue: { ...oldTask },
            newValue: { ...newTask }
        });
    
        redoStack.length = 0;
    }
    
    function undo() {
        const action = undoStack.pop();
    
        if (!action) {
            return;
        }
    
        gantt.updateTask(action.oldValue.id, action.oldValue);
    
        redoStack.push(action);
    }
    
    function redo() {
        const action = redoStack.pop();
    
        if (!action) {
            return;
        }
    
        gantt.updateTask(action.newValue.id, action.newValue);
    
        undoStack.push(action);
    }

    Regards,
    Markov

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.