An issues-only repository for the Bryntum project management component suite which includes powerful Grid, Scheduler, Calendar, Kanban Task Board and Gantt chart components all built in pure JS / CSS / TypeScript
function createTasks(selection, options) {
var promises = []; // To store the promises from each task creation
var firstAddedTask = null;
if (!selection || selection.length == 0) {
const added = window.gantt.taskStore.rootNode.appendChild({ ...options });
// Scroll to the added task
window.gantt.scrollRowIntoView(added);
// Start editing the new task's name field
gantt.features.cellEdit.startEditing({
record: added,
field: 'name'
});
// Run propagation to calculate new task fields
window.gantt.project.commitAsync();
} else {
const firstItem = selection[0];
selection.forEach(selected => {
// Handle the promise returned by addTask
window.gantt.addTask(firstItem, { ...options, above: true }).then((task) => {
if (!firstAddedTask) {
// Set the first task that was added
firstAddedTask = task;
// Scroll to the first added task and start editing
window.gantt.scrollRowIntoView(firstAddedTask);
gantt.features.cellEdit.startEditing({
record: firstAddedTask,
field: 'name'
});
}
return task;
})
.catch(err => {
console.error("Error adding task:", err);
});
});
}
}
window.createTasks = createTasks;
2. Run this in console:
`createTasks(gantt.selectedRecords, { name: 'New task', data: { duration: 1 } });`
3. Then:
`JSON.stringify(gantt.project.tasks)`
<img width="596" alt="Screenshot 2024-11-11 at 9 23 12 PM" src="https://github.com/user-attachments/assets/8ac3d47b-8a22-4614-a449-234121607388">
[Cycling when loading a gantt with 0 tasks](https://forum.bryntum.com/viewtopic.php?t=31051)
https://github.com/user-attachments/assets/07916609-6b11-4c92-8ae6-975bb205cf81
https://forum.bryntum.com/viewtopic.php?p=157669#p157669
Steps:
var gantt = new Gantt({ appendTo : 'container', dependencyIdField : 'sequenceNumber', rowHeight : 45, tickSize : 45, barMargin : 8, project : { autoSetConstraints : true, // automatically introduce
startnoearlier
constraint if tasks do not use constraints, dependencies, or manuallyScheduled autoLoad : true },columns : [ { type : 'name', width : 250 } ], });
await gantt.project.loadInlineData({ tasksData : [], resourcesData : [ { id : 1, name : 'Arcady' }, { id : 2, name : 'Don' } ], dependenciesData : [ { fromTask : 1, toTask : 2 } ], assignmentsData : [ { 'event' : 1, 'resource' : 1 }, { 'event' : 2, 'resource' : 2 } ], calendarsData : [ { id : 111, name : 'My cool calendar', intervals : [ { recurrentStartDate : 'on Sat at 0:00', recurrentEndDate : 'on Mon at 0:00', isWorking : false } ] } ],
});
function createTasks(selection, options) { var promises = []; // To store the promises from each task creation var firstAddedTask = null;
window.createTasks = createTasks;