Premium support for our pure JavaScript UI components


Post by bherford »

Hi Team,

I have a dataset of tasks that are set to readonly inside of my work breakdown structure. When I add a new task inside of a readonly task it updates the duration for the parent task, but when I remove it, the duration remains:
Before:

Screen Shot 2022-06-27 at 9.04.38 AM.png
Screen Shot 2022-06-27 at 9.04.38 AM.png (129.18 KiB) Viewed 155 times

After:

Screen Shot 2022-06-27 at 9.05.14 AM.png
Screen Shot 2022-06-27 at 9.05.14 AM.png (99.01 KiB) Viewed 155 times

Snippet for the add task button:

static get configurable() {

    return {
        cls : 'bottom-toolbar-wrapper',
        items : [
            {
                ref : 'addTaskButton',
                icon : 'b-fa b-fa-plus',
                cls : 'add-task-btn btn-edge',
                type : 'button',
                text : 'Add Task / Milestone',
                onAction : 'up.onAddTaskClick'
                
            }
        ]
    };    
}

async onAddTaskClick() {
    // Find today's date and stuff it into the new task startDate
    const today = new Date();
    const dd = String(today.getDate()).padStart(2, '0');
    const mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
    const yyyy = today.getFullYear();
    const startDate = `${yyyy}-${mm}-${dd}`
    const
        { gantt } = this,
        added     = gantt.taskStore.rootNode.appendChild({ name : 'New task', duration : 1, startDate });

    // run propagation to calculate new task fields
    await gantt.project.propagateAsync();

    // scroll to the added task
    await gantt.scrollRowIntoView(added);

    gantt.features.cellEdit.startEditing({
        record : added,
        field  : 'name'
    });

    Toast.show('New Task Created');
}

Post by marcio »

Hey,

I couldn't reproduce that with the code that you shared, could you please add a sample project with all the configurations that you're using?

In the meantime, you can try to use the https://www.bryntum.com/docs/gantt/api/Gantt/data/TaskStore#function-add and https://www.bryntum.com/docs/gantt/api/Gantt/data/TaskStore#function-remove functions to add/remove records, just be aware that the add method returns an array. So you'll need to destructure like this:

    const [added]     = gantt.taskStore.add({ name : 'New task', duration : 1, startDate });

Best regards,
Márcio


Post Reply