Gantt API

TreeGrid documentation

To control Gantt chart you can use all standard Extended API methods and events for TreeGrid controlling, like AddRow, DeleteRow, SetValue and so on.
You can change the data source values by API SetValue method and the Gantt chart will be automatically recalculated.
Many changes in Gantt chart are mirrored to other columns (e.g. Ancestors/Descendants), call CheckGantt before SetValue to check if the change is possible and also to update other Gantt columns accordingly.
API event bool

OnGanttStart

(TGrid grid)
Event called when Gantt chart is created for first time. Returns true to not create the Gantt chart (useful when it is already called RefreshGantt).
new 9.2 chg 10.0 upd 12.0 API event bool

OnGanttChange

(TGrid grid, TRow row, string col, string item, type new, type new2, type old, type old2, string action)
Event called before any item in Gantt chart has been changed by a user interaction in the Gantt.
Return true to cancel the change.
For the parameters see the OnGanttChanged event below.
new 6.0 chg 10.0 upd 12.0 API event void

OnGanttChanged

(TGrid grid, TRow row, string col, string item, type new, type new2, type old, type old2, string action)
Event called after any item in Gantt chart has been changed by a user interaction in the Gantt.
It is not called when the source cells are changed by edit - use here OnAfterValueChanged event instead.
It is also not called when resources are assigned from popup dialog.
It is called after the change is applied.
row, col is the Gantt chart cell.
item is the changed part, can be: MainX (X is plan as empty or 1,2,3,...), CompleteX, TextX, Flow, FlowText, Run, Constraint, Flags, FlagTexts, FlagIcons, Resources, Dependency, Lag

For Main bar: new = new Start date, new2 = new End date or new Duration, old = old Start date, old2 = old End date or duration, action = Move, Resize, Delete, DeleteAll, New, Correct
Since 9.2, the new2/old2 is duration if no GanttEnd column is defined, otherwise it is the end date.
To better control the main bar change use OnGanttMainChange / OnGanttMainChanged API events instead of OnGanttChange / OnGanttChanged.
For Complete:new = new Complete status, old = old Complete status, action = Change, DeleteAll
For Text:new = new Main bar Text, old = old Main bar Text, action = Change, DeleteAll
For Resources:new = new Resources text, old = old Resources text, action = Change (not called for choosing resources from popup menu), DeleteAll
For Flow:new = new Flow range, old = old Flow range, action = New, Delete, DeleteAll, Move, Resize removed 10.0
For FlowText:new = new FlowText, old = old FlowText, action = Change, DeleteAll removed 10.0
For Run bar: new = new Run value, new2 = new RunStart, old = old Run value, old2 = old RunStart value, action = Slide, Resize, Delete, DeleteAll, New, Move, MoveSource, Copy, Remove, RemoveSource It is possible to parse the new and old run values by GetGanttRun method.
To better control changes in individual Run boxes use OnGanttRunBoxChanged and OnGanttRunBoxNew events.
For RunComplete:new = new RunComplete status, old = old RunComplete status, action = Change, DeleteAll
For Flags:new = new Flags, old = old Flags, action = Move, Delete, DeleteAll, New
For FlagTexts:new = new FlagTexts, old = old FlagTexts, action = Delete, DeleteAll, New, Change
For FlagIcons:new = new FlagIcons, old = old FlagIcons, action = Delete, DeleteAll, Change
For Points:new = new Point or Point, old = old Points or Point, action = Move, Delete, DeleteAll, New
For Dependency: new = new dependency row ids (descendants), new2 = (new 12.0) the dependency object like returned by GetDependencies, old = old dependency row ids (descendants), action = New, Delete, Edit (lag, called twice)
For Lag:new = new DependencyLag value, old = old DependencyLag value, action = Change, Delete, DeleteAll removed 10.0
For Constraint:new = new Constraint value, new2 = (new) ConstraintType, old = old Constraint value, old2 = old ConstraintType for Change, action = New, Delete, Move, Change
new 6.4 API event string

OnGanttTip

(TGrid grid, TRow row, string col, string tip, object XY, string name)
Called to get a tip text for Gantt object to display it on mouse hover.
tip is the default tip text, return it or new tip.
XY are Gantt objects under mouse cursor returned by GetGanttXY.
name is the Gantt object name, can be: Main, Milestone, Flow, Run, Flags, Points, Constraints, Dependency.
new 9.1 API event bool

OnStartDragGantt

(TGrid grid, TRow row, string col, string name, int start, int end, int dir, object XY, string keyprefix, int clientX, int clientY)
Called on start dragging any object in Gantt chart except Run. For Run use OnDragGanttRun or OnGanttRunDrop instead.
Return true to suppress dragging.
For parameters description see OnDragGantt event.
new 9.1 upd 9.3 API event bool

OnEndDragGantt

(TGrid grid, TRow row, string col, string name, int start, int end, int oldstart, int oldend, int dir, object XY, string keyprefix, int clientX, int clientY, TRow ToRow)
Called on end dragging any object in Gantt chart except Run. For Run use OnDragGanttRun or OnGanttRunDrop instead.
Return true to cancel the change.
For parameters description see OnDragGantt event.
new 9.1 upd 9.3 API event int

OnDragGantt

(TGrid grid, TRow row, string col, string name, int start, int end, int oldstart, int oldend, int dir, object XY, string keyprefix, int clientX, int clientY, TRow ToRow)
Called during dragging any object in Gantt chart except Run. For Run use OnDragGanttRun or OnGanttRunDrop instead.
row, col is the Gantt cell.
name is the dragged Gantt object name, can be: Main, Milestone, Flow, Run, Flags, Points, Constraints.
start, end are new start and end dates of the Gantt object, as count of milliseconds since 1/1/1970. For milestone, flag, point and constraint is end the same as start.
oldstart, oldend are original start and end dates of the Gantt object.
dir is dragging direction, 1 left edge (resize), 2 right edge (resize), 3 both edges (move).
step is count of calling the OnDragGantt since dragging started. It is 0 for the first call.
XY is the dragged Gantt object returned by GetGanttXY.
keyprefix is prefix of shift keys: "Ctrl", "Alt", "Shift" and also mouse button "Right" or "Middle". The key is before the mouse, e.g. keyprefix='CtrlRight'.
clientX, clientY is mouse position on page.
ToRow (since 9.3) is the row under mouse cursor. Now only for flags can differ from the row.
Return null for normal behavior
Return 0 to suppress the last change
Return false to cancel dragging and restore original state
Return true to finish dragging and save this last change
new 10.0 API event type

OnStartDragGanttDependency

(TGrid grid, TRow row, string col, object XY, int color, bool start, string keyprefix, int clientX, int clientY)
Called on start dragging dependency.
row, col is actual Gantt cell where the dragging starts, XY is the Gantt object returned by GetGanttXY the dependency is being dragged from.
color is dependency color and shape (0-39) that will be assigned to the dependency during dragging. It can be different from final color according to the GanttAssignDependencies value.
start is 1 if the dependency starts from the box start, 0 if dependency starts from the box finish.
keyprefix is prefix of shift keys: "Ctrl", "Alt", "Shift" and also mouse button "Right" or "Middle". The key is before the mouse, e.g. keyprefix='CtrlRight'.
clientX, clientY is mouse position on page.
Return true to suppress dragging. Return JavaScript array as [color, start] to change these values for the new dependency.
new 10.0 API event type

OnDragGanttDependency

(TGrid grid, TRow row, string col, object XYSrc, TRow torow, object XYDest, bool end, string keyprefix, int clientX, int clientY)
Called during dragging dependency.
row, col is source cell where dragging started. XYSrc is the Gantt object returned by GetGanttXY where dragging started.
torow is destination row (under mouse cursor), XYDest is the Gantt object returned by GetGanttXY under mouse cursor, can be null if there is no bar under mouse that accept dependencies.
end is 1 if the dependency points to the destination box start, 0 if dependency points to the destination box finish.
keyprefix is prefix of shift keys: "Ctrl", "Alt", "Shift" and also mouse button "Right" or "Middle". The key is before the mouse, e.g. keyprefix='CtrlRight'
clientX, clientY is mouse position on page.
Return null for normal behavior.
Return -1 to not permit the dependency to attach to the destination bar. Ignored if there is no destination bar.
Return 0 to attach dependency to the destination bar finish. Ignored if there is no destination bar.
Return 1 to attach dependency to the destination bar start. Ignored if there is no destination bar.
Return false to cancel dragging and restore original state.
Return true to finish dragging and attach the dependency. Ignored if there is no destination bar.
new 10.0 API event bool

OnEndDragGanttDependency

(TGrid grid, object[ ] New, object[ ] Old)
Called after finish dependency dragging.
New is an array of new dependencies that will be added, in format like GetDependencies. Now the array contains only one dependency.
Old is an array of old dependencies that will be deleted, in format like GetDependencies. In case the new dependency replaces other dependencies between the same bars.
It is possible to modify parameters in New array to add dependency with different parameters (e.g. lag or type).
It is possible to remove some item from Old to not remove these dependencies.
Return true to suppress adding the dependencies (and deleting the old). Return true also in case you added the dependencies in this event handler.
Return false for default behavior.
new 13.0 API event string

OnEndDragGanttRange

(TGrid grid, int d1, int d2, string action)
Called after dragging range in Gantt finishes. Usually in Gantt header.
action can be ZoomGantt (action ZoomGantt) or SelectRun (action SelectGanttRunRange).
Return new action or empty string to suppress the action.
chg 9.0 upd 11.0 API method void

RefreshGantt

(int show = 255, string col = null)
Recalculates Gantt chart(s). Also shrinks chart to show only used date range.
show is binary mask of items to refresh (since 9.0, prior to 9.0 it was always 1 as 255 or 0 as 254).
&1 - if the changes will be displayed in chart. For 0 the grid needs to be rerendered.
&2 - if the width of Gantt will be recalculated. If the width of Gantt is changed, it also refreshes header and background.
&4 - if the GanttHeader and GanttBackground will be recalculated.
&8 - if the dependency settings will be recalculated for all tasks. If some of them changed, it refreshes all dependency lines in grid.
&16 - if all dependency lines in grid will be refreshed.
&32 - if recalculates GanttSlack
&64 - if recalculates Gantt charts in all variable rows
&128 - if recalculates Gantt charts in all fixed rows
&256 - (new 11.0) clears GanttRun cache, reads all the runs again from the source strings
For example RefreshGantt(179) means (1+2+16+32+128), so it recalculates Gantt width, all dependency lines, slack and fixed rows and shows changes.
When col set, recalculates only chart in this column, otherwise recalculates all charts in grid.
Should be called after any Gantt option changes by API, e.g. for zooming.
new 10.0 API variable bool

GanttUpdate

[0]
If set to 1, temporary disables creating the Gantt. Requires call of RefreshGantt ( ).
Use to speed up some action, like: Grid.GanttUpdate = 1; /* do here some long updating action */; Grid.GanttUpdate = 0; Grid.RefreshGantt ( );
upd 7.0 API method void

RefreshGanttDependencies

(int show = 1, string col = null)
Recalculates and redraws Gantt chart dependencies, useful when some rows show / hide.
(Since 7.0) For show = 2 recalculates also all cell dependency inputs, use when some global dependency setting changes (e.g. GanttIncorrectDependencies).
API method void

Recalculate

(TRow row, string col, bool show = 0)
Re-calculates grid after given cell changes, according to cell's or row's parameter Recalc.
Always recalculates fixed calculated rows.
It recalculates also Gantt chart in that row, if any.
new 9.3 API method void

RecalculateRows

(TRow[ ] rows, bool show = 0)
Recalculates given rows in given order.
Recalculates also Gantt chart in these rows. If the recalculation changes Gantt size, it refreshes whole Gantt chart.
It does not recalculate any other row (except the Gantt, see above), so if the calculation affects some other rows, they should be recalculated manually too.
Remember, this function breaks CalcOrder in tree, as stated above!
To display the changes in grid call the function with the second parameter (show) as 1.
The rows can be: a) array of TRow object, b) one TRow object, c) array of row ids (strings), d) one row id (string)
chg 10.0 upd 12.0 API method object

GetGanttXY

(TRow row, string col, int x, int y) or (int clientX, int clientY)
Returns Gantt objects on given position. x, y is the position inside the cell.
Useful to provide some custom action on click or on drag or on hover
The object has set these properties when given tag is on the given position:
string Type type of the top most (hovered) object, can be: "main", "run", "flags", "points", "constraints", "dependency"
Since 10.0 it can be also "line" for GanttLines, GanttBase and GanttFinish.
HTMLElement Main the main bar tag
int MainPlan(new 10.0) index (from 0) of the Main bar plan, see GanttCount.
int MainIndexindex (from 0) of the Main box when the bar is not continuous and more boxes exist in the cell
int MainType(changed 10.0) type of the Main tag, can be null (complete is null), 0 (not started part), 50 (incomplete part), 100 (complete part), Milestone
int MainXthe X position inside the Main tag.
int MainIcon(new 12.0) the side icon, 0 none, 1 left, 2 right
 
HTMLElement Main2the second main bar tag for incomplete tasks - the other part that is not on the given position. (removed 10.0)
int MainPosposition of the Main tag - 0 alone, 1 left side, 2 - right side (removed 10.0)
HTMLElement Flowthe real flow tag on given position (removed 10.0)
HTMLElement Flow2(new 6.4) the second real flow tag for incomplete tasks that is not on given position (removed 10.0)
int FlowPos(new 6.4) position of the incomplete Flow tag - 0 alone, 1 left side, 2 - right side (removed 10.0)
int FlowIndexindex (from 0) of the Flow tag when the flow is not continuous and more flow tags exists in the cell (removed 10.0)
int FlowXthe X position inside the Flow tag (removed 10.0)
 
HTMLElement Runthe continuous run tag on given position
int RunIndexindex (from 0) of the Run box inside its cell
int RunXthe X position inside the Run tag
int RunTypetype of the Run box
string RunClass(new 10.0) class of the Run box
string RunId(new 10.0) id of the Run box, if set
string RunGroup(new 10.0) group of the Run box, if set
int RunState(new 10.0) state of the Run box, bit array: 1 - disabled, 2 locked, 4 selected, 8 added, 16 deleted, 32 moved, 64 resized, 128 changed.
string RunContainer(new 13.0) The top Run container, only if no box is on the position. If set, the Run and RunX are related to the container and RunIndex and the others are for the first box in the container.
string[] RunContainers(new 13.0) All Run containers, only if no box is on the position. The last one is the RunContainer.
 
HTMLElement Flagthe flag tag on given position
HTMLElement FlagText(new 10.0) the flag text tag on given position
int FlagIndexindex (from 0) of the Flag tag when the cell contains more flags
int FlagXthe X position inside the Flag tag.
 
HTMLElement Point(new 6.4) the point tag on given position
int PointIndex(new 6.4) index (from 0) of the Point tag when the cell contains more points
int Point X(new 6.4) the X position inside the Point tag.
 
HTMLElement Constraintthe constraint tag on given position
int ConstraintXthe X position inside the Constraint tag.
string ConstraintTypecan be "MinStart", "MaxStart", "MinEnd", "MaxEnd"
 
int Line(new 10.0) Index of the line in GanttLines or -1 for GanttBase or -2 for GanttFinish
int LineLeft(new 10.0) Left position in pixels
int LineWidth(new 10.0) Width in pixels
int LineStart(new 10.0) Line start date in milliseconds
int LineEnd(new 10.0) Line end date if any, in milliseconds
string LineClass(new 10.0) Line CSS class part
int LineFlags(new 10.0) Flags of the line. &1 -if the line is editable, &2 - if the line can be placed on excluded dates, &4 if the LineStart is end date
 
string DependencyFrom(new 10.0) row id the dependency comes from
string DependencyFromBox(new 10.0) main bar plan number or run box id the dependency comes from
string DependencyTo(new 10.0) row id the dependency goes to
string DependencyToBox(new 10.0) main bar plan number or run box id the dependency goes to
string DependencyType(new 10.0) type of the dependency like fs, ss, sf, fs. Can be empty for fs.
int DependencyStart(new 10.0) Start date of the dependency, in milliseconds since 1/1/1970. It does not contain the lag.
int DependencyEnd(new 10.0) End date of the dependency, in milliseconds since 1/1/1970
int DependencyLag(new 10.0) Lag of the dependency start in milliseconds.
int DependencySpan(new 10.0) Maximal span of the dependency in milliseconds
int DependencyColor(new 10.0) Number of color / shape of the dependency, 0 - 40 or null
 
string DependencyStartLeftlist of ids of all rows that are connected from this left side. The ids are separated by Lang.ValueSeparator (';'' by default) (removed 10.0)
string DependencyStartRightlist of ids of all rows that are connected from this right side. (removed 10.0)
string DependencyEndLeftlist of ids of all rows that are connected to this left side. (removed 10.0)
string DependencyEndRightlist of ids of all rows that are connected to this right side. (removed 10.0)
new 8.0 API method object

GetGanttHeaderXY

(TRow row, string col, int x, int y) or (int clientX, int clientY)
Returns object for specific cell of Gantt header.
Useful to provide some custom action on click or on drag or on hover, for example to show special tip for header cell in OnTip event.
The object has set these properties:
int Header -index of the GanttHeader attribute, 1 - 5
int Start - start date shown in the cell
int End - start date of the next cell
string Units - GanttUnits used in the cell, e.g. "d" or "w"
int X, Y - click position relative to the cell in pixels
int X, Y - click position relative to the cell in pixels
new 6.3 chg 7.0 API method type

CheckGantt

(TRow row, string col, string val)
Checks if given cell can get value val, if it is correct for Gantt chart.
If the cell cannot be changed to val, it returns false and does not do any change.
If the value is correct, it returns the val.
In some cases (since 7.0) it can change the val (e.g. because of exclude settings), it returns the new value.
If it does not return false, it has already done changes in grid, so the value must put into the cell.
It updates Gantt chart when the source column value changes to val (e.g. mirroring Ancestors / Descendants or End / Duration).
Call it before the cell change to know if it can be done and to provide required changes in Gantt chart.
This method is called automatically when the cell is changed by editing or from Gantt chart by a user.
It check circular dependencies, percentage complete, negative duration, End>Start.
The checking depends on GanttCheck settings.
To set value to Gantt source cell by API use: val = grid.CheckGantt(row,col,val); if(val!==false) grid.SetValue(row,col,val,1);
new 7.0 API event type

OnCheckGantt

(TGrid grid, TRow row, string col, string newval)
Called to check new Gantt value after editing.
It is called for every cell, even for all not Gantt cells. Called only when Gantt chart defined and GanttCheck is not 0.
Return false to suppress the change and continue editing
Return true to permit the change without further default checking
Return null to default behavior
Return changed value to be used instead newval. The default checking will be still done for this changed value.
newval is new value for the cell, col is cell column, not Gantt column.
new 6.3 API method bool

HasGantt

( )
Returns true if in the grid exists Gantt column
new 6.3 API method bool

HasDependencies

( )
Returns true if the Gantt chart has defined some dependencies
new 6.3 API method int

GetGanttDate

(int pos, string col = null)
Returns exact date (as count of milliseconds) on the given position in chart, in pixels
new 6.3 API method int

GetGanttPos

(int pos, string col = null)
Returns position in chart, in pixels of the date (as count of milliseconds)
new 10.0 API method int

GanttUnitsDuration

(string units = null, string col = null)
Returns duration of given units as GanttUnits in milliseconds, e.g. for "m" returns 60000.
If units = null, returns duration for GanttDataUnits.
If units = 0, returns duration for GanttUnits.
For special variable duration units like 'M', 'M3', 'M6' and 'y' returns average duration.
new 6.3 upd 11.0 API method int

RoundGanttDate

(int date, int round, int base = null, string col = null, string units = null, TRow row = null)
Rounds and returns the given Gantt date (as count of milliseconds) according to the round.
round is bit array:
1 - round to beginning of the unit, 2 - round to end of the unit,
4 - round to last work time before, 8 - round to first work time after
16 - like 1, but after rounding to worktime, 32 - like 2, but after rounding to worktime
48 - move back to original unit if it was moved to another because it had no work time
64 - input (date and base) is position in pixels instead of date, 128 - returns position in pixels instead of date
256 - (new 11.0) adds / subtracts GanttPage position for values 64 and 128.
For example round = 1+4+32+128 rounds to beginning, next to workday before, next to end and returns position in pixels
base is base date (count of milliseconds), if set, to the resulted date is added difference between base and base rounded to units.
units can be set to any Gantt units like 'd' or 'h' or null for GanttUnits attribute.
(new 8.0) row is row object used to calculate worktime when the row has set custom GanttCalendar.
new 6.4 upd 8.0 API method int

DiffGanttDate

(int start, int end, string units = null, string last = null, string col = null, TRow row = null)
Returns count of units between dates, in workdays.
start and end can be set set as count of millisecond or by English date string.
units are standard GanttDataUnits like 'd' or 'h'. If not set, GanttDataUnits are used.
last can be set to standard GanttDataUnits like 'd' or 'h' to add this unit to the end date. If set to 1, one GanttDataUnits is added.
col - gantt column to use, if not set, the first gantt column in grid will be used.
If set holidays (GanttExclude) and the units are bigger than exclude units, it returns count of units that contain at least one work time unit.
(new 8.0) row is row object used to calculate worktime when the row has set custom GanttCalendar.
new 6.7 upd 8.0 API method int

IncGanttDate

(int start, int dur, string units = null, bool beg = false, string col = null, TRow row = null)
Returns start date increased for dur count of units.
start can be set as count of millisecond or by English date string.
dur is count of units in workdays, without excluded dates. Can be negative to decrease the date.
units are standard GanttDataUnits like 'd' or 'h'. If not set, GanttDataUnits are used. Should not be 'M' and bigger units.
beg - if the resulted date is in holidays, for 0 it returns last work date before and for 1 first work date after.
col - gantt column to use, if not set, the first gantt column in grid will be used.
(new 8.0) row is row object used to calculate worktime when the row has set custom GanttCalendar.