Show / Hide Table of Contents

Undo/Redo

This is used if you've made a mistake or by any other reason you want to undo the changes you have made. You can undo and redo many actions in FlowChart JS and you have a counters for both. Evey undo/redo action is saved in the Window sessionStorage property and can be saved in the database too.

How to add undo/redo buttons:

You just need to add the menuBar:

 

chart.uiMenuBar.show();
    

Shortcuts

CTRL + Z - undo
CTRL + Y - redo

How to update the database:

With undo/redo option you need to use the onChanged method to update the database:

 

chart.onChanged(function(args){
    var data = chart.json();
    // post data to server
    // ...
});
    

UI customization:

You can use the onChange method to crete your own UI.

HTML:

 
        
<button id="btn_undo">Undo</button>
<button id="btn_redo">Redo</button>
    
JS:
 

let btn_undo = document.getElementById('btn_undo');
let btn_redo = document.getElementById('btn_redo');


let refreshBtnUI = function(){
    btn_undo.innerHTML = `undo (${chart.undoStepsCount()})`;          
    btn_redo.innerHTML = `redo (${chart.redoStepsCount()})`;        
    btn_undo.disabled = chart.undoStepsCount() == 0;
    btn_redo.disabled = chart.redoStepsCount() == 0;
}

chart.onUndoRedoChanged(function(){        
    refreshBtnUI();
    return false;
});

btn_undo.addEventListener('click', function(){
    chart.undo();
});

btn_redo.addEventListener('click', function(){
    chart.redo();
});
    
Here is a code demo: