Documentation
Users change a plan in the chart itself: they drag bars, drag the ends of bars, change the progress, draw connections and edit tasks in a window. This page shows how your code learns about each change, how to limit what users may change, how to adapt the task editor, and how to send the changes to a server.
The examples are complete pages like the ones in the getting-started guide. The guide shows how to load the files and how to change tasks with methods (Edit tasks); this page does not repeat that.
new jqxGantt('#gantt', ...) draws the chart in a jqx-gantt-chart element inside #gantt. That element raises the chart's events as DOM events. They bubble, so a listener on #gantt receives them, with the details in event.detail.
The first example writes the events to a list under the chart. Its markup:
<p>
<button type="button" id="shift">Move every task a week later</button>
<button type="button" id="clear">Clear the log</button>
</p>
<div id="demo">
<div id="gantt"></div>
<ol id="log" aria-live="polite"></ol>
</div>
The script listens on #gantt:
// The chart raises its events on the jqx-gantt-chart element inside #gantt. They bubble,
// so a listener on #gantt receives them, with the details in event.detail.
const host = document.getElementById('gantt');
host.addEventListener('dragEnd', (event) => {
const { item, dateStart, dateEnd } = event.detail;
write(`dragEnd: ${item.label} now runs ${day(dateStart)} - ${day(dateEnd)}`);
});
host.addEventListener('resizeEnd', (event) => {
const { item, dateStart, dateEnd } = event.detail;
write(`resizeEnd: ${item.label} now runs ${day(dateStart)} - ${day(dateEnd)}`);
});
host.addEventListener('progressChangeEnd', (event) => {
const { item, progress } = event.detail;
write(`progressChangeEnd: ${item.label} is ${Math.round(progress)}% done`);
});
The same events reach other kinds of listeners, with the details in another place:
| Listener | Details |
|---|---|
document.getElementById('gantt').addEventListener(name, handler), as above | event.detail |
document.querySelector('#gantt jqx-gantt-chart').addEventListener(name, handler) | event.detail |
$('#gantt').on(name, handler) | event.originalEvent.detail |
gantt.addEventListener(name, handler), the method of the widget that new jqxGantt returns | event.originalEvent.detail |
Other jQWidgets widgets put their details in event.args. For the Gantt chart's events it is undefined in 27.1.0 and earlier. event.preventDefault() works with every listener.
Where a detail says what kind of item an event is about ('task' or 'connection', for example), the field is named type. The API reference calls it dataType; in 27.1.0 and earlier there is no dataType field.
Each change that a user makes with the mouse raises a pair of events: one when it starts and one when it ends.
| The user | Events | event.detail |
|---|---|---|
| drags a bar | dragStart, dragEnd | id, item (a copy of the task), dateStart, dateEnd |
| drags the end of a bar | resizeStart, resizeEnd | id, item, dateStart, dateEnd |
| drags the triangle under a selected bar | progressChangeStart, progressChangeEnd | id, item, progress |
The Start events carry the values before the change, the End events the new ones. The dates are Date objects worked out from where the bar lands, so they usually have a time of day (the log shows only the day). progress is not rounded. The API reference also lists an index for the progress events, which 27.1.0 and earlier do not send.
Moving or resizing a task raises no itemUpdate: to learn about these changes, listen to dragEnd and resizeEnd.
The progress triangle shows only under a selected task, so a user clicks a bar first. A click on another bar adds it to the selection, and a second click on a selected bar unselects it. Each click raises change, whose detail has type ('task'), value (the selected ids) and oldValue (the ids selected before), and itemClick, with id, item, type and the originalEvent.
A task can be split into segments (see What users may change). Dragging a segment, or one of its ends, raises the same events with the segment in event.detail.segment.
event.preventDefault() in dragStart, resizeStart, progressChangeStart or connectionStart cancels what the user started. The log page keeps finished tasks in place:
// The events whose name ends in Start can be cancelled. A task that is done may not move.
host.addEventListener('dragStart', (event) => {
if (event.detail.item.progress === 100) {
event.preventDefault();
}
});
Research is 100% done, so dragging it does nothing and no dragEnd follows. A cancelled dragStart is raised again on each mouse move while the button is down; keep its handler short and do not show a message from it. The log's own dragStart listener checks event.defaultPrevented for that reason.
In 27.1.0 and earlier, cancelling resizeStart does not stop the mouse: the same drag then moves the task (dragStart, dragEnd). To keep the dates of a task, give it disableDrag and disableResize instead.
Users draw a connection from the dot at the end of one bar to the dot at the start of another (see Task connections in the guide). Three events follow:
| Event | event.detail |
|---|---|
connectionStart | startIndex, the row of the first task. Cancel it to stop the connection. |
itemInsert | type: 'connection' and item: { source, target, type }, with row indexes |
connectionEnd | id, startIndex, startTaskId, endIndex, endTaskId, type (0 to 3) |
Use connectionEnd: it has the task ids, which do not change when rows move. A double-click on a connection line opens a window that asks whether to delete it; its OK button deletes the connection and raises itemRemove with type: 'connection'.
Three events report items that were added, changed or removed, whether by a user or by your code:
| Event | Raised by | event.detail |
|---|---|---|
itemInsert | insertTask, createConnection, a connection that a user draws | type, item (the id is item.id) |
itemUpdate | updateTask, OK in the task editor | type, id, item with the new values |
itemRemove | removeTask, removeConnection, Delete in the task editor, a deleted connection | type, id, item |
The methods are described in the guide's Edit tasks.
The arrow of a project in the tree, and the expand and collapse methods, raise expand and collapse. Their detail has the project's id, item, index (its row) and label.
beginUpdate() stops the chart from redrawing until endUpdate(), which draws all the changes in one go. The log page's first button moves every task a week later:
// Many changes at once: the chart does not redraw between beginUpdate and endUpdate.
document.getElementById('shift').addEventListener('click', () => {
const week = 7 * 24 * 60 * 60 * 1000;
gantt.beginUpdate();
for (const task of gantt.getTasks()) {
gantt.updateTask(task.id, {
dateStart: new Date(task.dateStart.getTime() + week),
dateEnd: new Date(task.dateEnd.getTime() + week)
});
}
gantt.endUpdate();
});
The two methods raise beginUpdate and endUpdate events. The changes between them raise no itemInsert, itemUpdate or itemRemove, so code that tracks changes through these events has to record batched changes itself.
In 27.1.0 and earlier, endUpdate() throws Cannot read properties of undefined (reading 'rows') when the batch inserted or removed a task and the chart shows no resources: the tasks are drawn, but the endUpdate event is not raised. Set hideResourcePanel: true on such a chart. A batch of updateTask calls, as above, works without it.
By default users can move and resize every task, change its progress and edit it. Options turn each of these off for the whole chart, and two fields of a task turn them off for that task. This page has a check box for each option:
<fieldset id="options">
<legend>Users may not</legend>
<label><input type="checkbox" data-option="disableTaskDrag"> move tasks</label>
<label><input type="checkbox" data-option="disableTaskResize"> resize tasks</label>
<label><input type="checkbox" data-option="disableTaskProgressChange"> change the progress</label>
<label><input type="checkbox" data-option="disableSegmentDrag"> move segments</label>
<label><input type="checkbox" data-option="disableSegmentResize"> resize segments</label>
<label><input type="checkbox" data-option="disableWindowEditor"> open the editor</label>
<label><input type="checkbox" data-option="disabled"> do anything</label>
</fieldset>
const gantt = new jqxGantt('#gantt', {
theme: 'fluent',
width: '100%',
height: 'auto',
view: 'month',
monthScale: 'week',
treeSize: '30%',
// How fast the timeline scrolls while a bar is dragged to its edge (5 by default).
autoScrollStep: 10,
source: [
{
id: 'relaunch',
type: 'project',
label: 'Website relaunch',
dateStart: '2026-03-02T00:00:00',
dateEnd: '2026-05-29T00:00:00',
expanded: true,
tasks: [
// Done: it keeps its dates.
{
id: 'research', type: 'task', label: 'Research', dateStart: '2026-03-02T00:00:00', dateEnd: '2026-03-20T00:00:00', progress: 100,
disableDrag: true, disableResize: true
},
{ id: 'design', type: 'task', label: 'Design', dateStart: '2026-03-23T00:00:00', dateEnd: '2026-04-17T00:00:00', progress: 40 },
// A task done in two parts, with a pause between them.
{
id: 'build', type: 'task', label: 'Build', dateStart: '2026-04-20T00:00:00', dateEnd: '2026-05-29T00:00:00',
segments: [
{ label: 'Front end', dateStart: '2026-04-20T00:00:00', dateEnd: '2026-05-08T00:00:00' },
{ label: 'Back end', dateStart: '2026-05-13T00:00:00', dateEnd: '2026-05-29T00:00:00' }
]
}
]
},
{ id: 'content', type: 'task', label: 'Content migration', dateStart: '2026-04-13T00:00:00', dateEnd: '2026-05-22T00:00:00' }
]
});
// Each check box sets the option of the same name.
for (const box of document.querySelectorAll('[data-option]')) {
box.addEventListener('change', () => {
gantt[box.dataset.option] = box.checked;
});
}
| Option | When true |
|---|---|
disableTaskDrag | Bars cannot be moved. They can still be resized. |
disableTaskResize | The ends of the bars no longer change the duration: dragging an end moves the whole task. |
disableTaskProgressChange | The progress triangle does nothing. |
disableSegmentDrag | Dragging a segment moves the whole task, not the segment alone. |
disableSegmentResize | The ends of segments no longer resize them. |
disableWindowEditor | No task editor: a double-click opens nothing, and so does openWindow. |
disabled | The chart ignores the mouse: no moving, resizing, selection or editor, and no events. It is drawn faded. |
Research has disableDrag: true and disableResize: true: it keeps its dates whatever the options say, and dragging it raises no events. Its progress can still change.
Build has segments: it is drawn as two parts with a pause between them. Each segment can be moved and resized on its own, and the task's dates follow its first and last segment.
When a user drags a bar near the left or right edge of the timeline, the timeline scrolls. autoScrollStep sets how fast (5 by default; this page uses 10), and disableAutoScroll: true turns it off. This page shows the months in weeks (view: 'month', monthScale: 'week'), so the timeline is wider than its column and has room to scroll.
A double-click on a bar, or on a row of the tree, opens the task editor. openWindow(id) opens it from code and closeWindow() closes it. The editor has three tabs: General with the task's fields, Dependency with its connections, and Segments. OK saves the changes and raises itemUpdate; Delete asks for confirmation, then removes the task and raises itemRemove.
The editor is a jqx-window element that the chart adds to the end of the <body>, outside #gantt. Style it with selectors that do not start with #gantt.
This page gives the editor an Owner field, leaves out the Segments tab and hides Delete for projects. Its Edit Design button opens the editor with openWindow('design'):
// The General tab of the editor has a field for each column whose value the task has.
const taskColumns = [
{ label: 'Task', value: 'label', size: '60%' },
{
label: 'Owner',
value: 'owner',
// A field of your own: create it, show the task's value, read it back on OK.
customEditor: () => {
const field = document.createElement('div');
field.className = 'owner-editor';
field.innerHTML = '<label for="owner">Owner</label><select id="owner"></select>';
field.querySelector('select').append(...owners.map((name) => new Option(name)));
return field;
},
setCustomEditorValue: (editor, label, value) => {
editor.querySelector('select').value = value;
},
getCustomEditorValue: (editor) => editor.querySelector('select').value
}
];
// Called each time before a window opens: type is 'task', 'confirm' or 'connection'.
function customizeWindow(target, type, item) {
if (type === 'task') {
target.classList.toggle('project-editor', item.type === 'project');
}
}
The chart gets them as options: taskColumns: taskColumns, popupWindowCustomizationFunction: customizeWindow, and popupWindowTabs: ['general', 'dependency'], which leaves out the Segments tab. Each task in the data source has an owner.
document.getElementById('edit').addEventListener('click', () => {
gantt.openWindow('design');
});
The General tab has a field for each column in taskColumns whose value the task has: Design has an owner, so its editor has an Owner field, and a task without one gets none. Without taskColumns the tab has a single field, Label. Fields of task columns are covered in the guide's Task tree columns.
A column's customEditor makes a field of your own. It returns the element of the field; setCustomEditorValue(editor, label, value) puts the task's value in it, and getCustomEditorValue(editor) returns the value that OK stores in the task. editor is the element that holds your field. The chart keeps the owner field in the task, shows it in the Owner column, and sends it in the itemUpdate item.
popupWindowTabs lists the tabs to show: 'general', 'dependency' and 'segments'.
The function in popupWindowCustomizationFunction (customizeWindow here) runs each time before a window opens, with three arguments. target is the jqx-window element, type is 'task' for the editor, 'confirm' for the question that Delete asks and 'connection' for deleting a connection, and item is a copy of the task for the first two.
The chart fills the window after the function returns, so changes to its heading, buttons and fields are overwritten. Classes and styles of the window stay. This page adds a class to the window of a project, and its stylesheet hides Delete in it:
/* The editor of a project has no Delete button (see popupWindowCustomizationFunction). */
.project-editor .jqx-popup-window-button.delete {
visibility: hidden;
}
| Event | When | event.detail |
|---|---|---|
opening | Before the editor or the connection window opens (not the confirmation). preventDefault() keeps it closed. | type, target |
open | After a window opens, the confirmation included | type, target |
closing | Before a window closes. preventDefault() keeps it open. | type, target |
close | After a window closes | type, target |
opening does not say which task the window is for. This page uses its type to keep users from deleting connections:
// Double-clicking a connection opens a window that deletes it. Keep it closed.
host.addEventListener('opening', (event) => {
if (event.detail.type === 'connection') {
event.preventDefault();
status.textContent = 'Connections cannot be deleted on this page.';
}
});
host.addEventListener('itemUpdate', (event) => {
const { item } = event.detail;
status.textContent = `${item.label} saved, owner ${item.owner}.`;
});
Cancelling closing after OK keeps the window open, but by then OK has already saved the fields and raised itemUpdate. It cannot be used to reject what the user typed.
The chart does not talk to a server. To save what users change, collect the changes from the events and send them yourself. This page notes the ids of changed tasks, the ids of removed tasks and whether the connections changed:
// What changed since the last save: the ids of changed and removed tasks, and the connections.
const changed = new Set();
const removed = new Set();
let connectionsChanged = false;
function showPending() {
const names = [...changed, ...removed];
if (connectionsChanged) {
names.push('connections');
}
status.textContent = names.length ? `Unsaved changes: ${names.join(', ')}` : 'No changes.';
}
function markChanged(event) {
changed.add(event.detail.id);
showPending();
}
// After a task is removed, 27.1.0 and earlier can keep a connection of that task (drawn between
// two other rows) and stop drawing others. Create them again from the task ids.
function rebuildConnections(removedId) {
const kept = gantt.getConnections().filter((c) => c.startTaskId !== removedId && c.endTaskId !== removedId);
gantt.removeAllConnections();
for (const c of kept) {
gantt.createConnection(c.startTaskId, c.endTaskId, c.type);
}
}
host.addEventListener('dragEnd', markChanged);
host.addEventListener('resizeEnd', markChanged);
host.addEventListener('progressChangeEnd', markChanged);
host.addEventListener('itemUpdate', (event) => {
if (event.detail.type === 'task') {
markChanged(event);
}
});
host.addEventListener('itemRemove', (event) => {
if (event.detail.type === 'task') {
const id = event.detail.id;
changed.delete(id);
removed.add(id);
rebuildConnections(id);
}
connectionsChanged = true;
showPending();
});
host.addEventListener('connectionEnd', () => {
connectionsChanged = true;
showPending();
});
Save sends the changes in one POST request with fetch:
// 'YYYY-MM-DD' of the local date
const day = (date) => {
const d = new Date(date);
return `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, '0')}-${String(d.getDate()).padStart(2, '0')}`;
};
document.getElementById('save').addEventListener('click', async () => {
if (!changed.size && !removed.size && !connectionsChanged) {
return;
}
// Send each changed task as it is now, the removed ids and all connections.
const body = {
updated: [...changed].map((id) => {
const task = gantt.getTask(id);
return { id, label: task.label, dateStart: day(task.dateStart), dateEnd: day(task.dateEnd), progress: Math.round(task.progress || 0) };
}),
removed: [...removed],
connections: gantt.getConnections().map((c) => ({ from: c.startTaskId, to: c.endTaskId, type: c.type }))
};
status.textContent = 'Saving...';
try {
const response = await fetch('/api/plan', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(body)
});
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
changed.clear();
removed.clear();
connectionsChanged = false;
status.textContent = 'Saved.';
}
catch (error) {
// Keep the changes, so that the next click sends them again.
showPending();
status.textContent += ` Not saved (${error.message}).`;
}
});
The request body has three parts:
| Field | Content |
|---|---|
updated | Each changed task as it is now: id, label, dateStart and dateEnd as 'YYYY-MM-DD', and progress rounded |
removed | The ids of the removed tasks |
connections | All connections, each as { from, to, type } with task ids |
The page reads each changed task with getTask when it saves, so a task changed several times is sent once, with its latest values. If the server answers with an error, the page keeps the changes and the next click sends them again. On the server, check every id and write with parameterised queries.
Changes your own code makes with updateTask raise itemUpdate as well, so they are saved the same way, except inside beginUpdate/endUpdate (see Many changes at once).
In 27.1.0 and earlier the connections are not always right after a task is removed, whether by removeTask or by Delete in the editor. A connection of the removed task can stay, drawn between two other rows, and other connections can keep old row numbers or no longer be drawn. rebuildConnections creates the remaining connections again from their task ids after each removal. When you remove tasks from code, the guide's Edit tasks shows how to remove a task's connections first.