RadiantQ jQuery Gantt Package
Adding Undo actions Programmatically
Previous Topic  Next Topic 

You will often have to add custom actions into the gantt's ActionManager when you have the Undo feature enabled. As mentioned in the previous topic, when Undo is enabled, you should not make any changes on the gantt model programmatically without going through the ActionManager.


Some common actions that you will have to add manually into the ActionManager are:


Adding new Tasks


Use the built-in AddAction to add a new task in the gantt.

         var newTask =  {

             "Name": "New Task ",

             "ID": ganttControl.Model.GetNewID(),

             "StartTime": new Date("2014/02/02"),

             "Effort": new RQTimeSpan(0, 12, 30, 0, 0),

             "ProgressPercent": 50,

             "Description": "Description of Task"

          };

          var addAction = new RadiantQ.Gantt.AddAction(ganttControl, newTask);

          ganttControl.ActionManager.RecordAction(addAction);


This Action removes the added task object from the list on undo and adds it back again on redo.


Deleting an existing Task


Use the build-in DeleteAction action to delete an existing task in the gantt:


        var activity = ganttControl.SelectedActivity;

        if (activity)

        {

            if (activity.ChildActivities_M().length > 0)

            {

                alert("Children have to be deleted before parent to support Undo.");

                return;

            }

            var delAction = new RadiantQ.Gantt.DeleteAction(ganttControl, activity);

            ganttControl.ActionManager.RecordAction(delAction);

        }

        else

            alert("Select an activity first, before delete.");


This Action caches the deleted object and adds it back into the list on undo.


More built-in Actions


There are a whole lot of other built-in undo actions in the RadiantQ.Windows.Controls.Gantt namespace like the following:


This is illustrated in this samples:


In HTML                : ..\Samples\GanttControlUndoRedo.htm.


© RadiantQ 2022. All Rights Reserved.