Canvas setup
In a canvas app, the Gantt shows your table and raises events when users edit, add or open tasks; your formulas do the saving. Put a Patch in OnTaskChange and OnAddTask.
The examples use a table called Tasks with these columns: Name, Start, End, Progress, Parent (a lookup to Tasks) and Predecessor (a lookup to Tasks). The table’s ID column is Task. Replace the names with yours. Model-driven setup lists the column types.
1. Allow code components
Once per environment, an admin turns on Allow publishing of canvas apps with code components. See Install.
2. Add the Gantt
- Open your canvas app in Power Apps Studio. Add your table under Data: Add data, then Tasks.
- Go to Insert, Get more components, then the Code tab. Tick Ninth Forge Gantt and select Import.
- Go to Insert, Code components, then Ninth Forge Gantt, and size it to the screen.
3. Bind it
| Property | Value |
|---|---|
| Items | Tasks, or a Filter of it |
| Fields (Advanced tab, each column’s logical name in quotes) | taskStart "cr123_start", taskEnd "cr123_end", and any of taskProgress, taskOwner, taskMilestone, taskBaselineStart, taskBaselineEnd. If names show as “(no name)”, set taskName to your name column. |
| Save mode | Leave it on Auto. Canvas apps always save through OnTaskChange. |
| Licence key | A formula that reads the Ninth Forge licence keys environment variable (below). |
The other settings (title, zoom, theme, accent, grid columns, working week) work as in model-driven apps.
Phases and dependencies
Canvas apps can’t map a lookup column to a code component, so leave taskParent and taskPredecessor empty. Instead, give the Gantt text columns that hold the IDs. With AddColumns, rows get temporary keys, so map the row’s own ID as well. Wrap it in ShowColumns and list every column you map, so the app loads them; without it, names show as “(no name)” and bars are missing:
ShowColumns(
AddColumns(Filter(Tasks, true),
TaskKey, Text(ThisRecord.Task),
ParentKey, Text(ThisRecord.'Parent'.Task),
PredKey, Text(ThisRecord.Predecessor.Task)),
TaskKey, ParentKey, PredKey, cr123_name, cr123_start, cr123_end, cr123_progress)Then set taskKey "TaskKey", taskParentKey "ParentKey" and taskPredecessorKey "PredKey", and set taskName to your name column. Put quotes around 'Parent', because Parent is a reserved word in Power Fx.
If Studio keeps showing “Loading tasks…” after you change these settings, save the app, close Studio and open the app again. The Gantt then loads normally.
Licence key
In model-driven apps the Gantt reads your keys from the Ninth Forge licence keys environment variable. Canvas apps can’t. Instead, select the screen (not the Gantt), add the Environment Variable Values table under Data, then set Licence key to:
LookUp(
'Environment Variable Values',
'Environment Variable Definition'.'Schema Name' = "nf_NinthForgeLicenceKeys"
).ValueIf the Gantt is selected when you add the table, Studio offers to make the table its data source and replaces Items. Cancel, select the screen and add it again.
Don’t paste the key itself into the app.
4. Save edits: OnTaskChange
Every edit sets Self.lastChange to JSON describing the change, then raises OnTaskChange. The JSON has the task id and only the fields that changed: name, start, end, date (milestones), progress, parentId and dependsOn. The chart keeps the edit on screen while it waits up to 10 seconds for the record to change. If the record doesn’t change, the chart puts the task back and shows “Not saved”.
With(
{ c: ParseJSON(Self.lastChange), r: LookUp(Tasks, Task = GUID(Text(ParseJSON(Self.lastChange).id))) },
Patch(Tasks, r, {
Name: Coalesce(Text(c.name), r.Name),
Start: Coalesce(DateValue(Text(c.start)), DateValue(Text(c.date)), r.Start),
End: Coalesce(DateValue(Text(c.end)), r.End),
Progress: Coalesce(Value(c.progress), r.Progress),
Predecessor: If(
IsBlank(c.dependsOn), r.Predecessor,
CountRows(Table(c.dependsOn)) = 0, Blank(),
LookUp(Tasks, Task = GUID(Text(First(Table(c.dependsOn)).Value)))
)
})
)5. Add tasks: OnAddTask
“+ Add task”, Insert and the row menu set Self.addRequest to { parentId, afterId, start } and raise OnAddTask. Create the row however you like. For example, a default row:
With(
{ a: ParseJSON(Self.addRequest) },
Patch(Tasks, Defaults(Tasks), {
Name: "New task",
Start: Coalesce(DateValue(Text(a.start)), Today()),
End: Coalesce(DateValue(Text(a.start)), Today()) + 4,
'Parent': If(IsBlank(Text(a.parentId)), Blank(), LookUp(Tasks, Task = GUID(Text(a.parentId))))
})
)Or navigate to a form screen in new mode and prefill it from a.
6. Open tasks: OnOpenTask
Double-click or Enter on a task sets Self.selectedTaskId and raises OnOpenTask:
Set(varTask, LookUp(Tasks, Task = GUID(Self.selectedTaskId))); Navigate(EditScreen)On EditScreen, add an Edit form with DataSource Tasks and Item varTask. Add a Save button (SubmitForm(Form1); Back()) and a Cancel button (Back()).
Check it
In Play mode (F5):
- drag a bar and refresh the data: it stays moved
- Alt+↑ raises progress by 10%
- link two tasks (drag the dot, or L then Enter)
- F2 renames a task
- “+ Add task” adds a row
- double-click opens your edit screen
Licensing note
Dataverse is a premium connector, so a canvas app on Dataverse needs premium Power Apps licences anyway. The Gantt itself makes no network calls, so it doesn’t add any licensing requirement.
Last updated