Our state of the art Gantt chart


Post by shimnx »

The maintask should be assigned to nobody ,only the subtask can be assigned
in current situation it works ,but when i create a new maintask it can be assigned

Attachments
媒体3.mp4
(11.46 MiB) Downloaded 37 times

Post by tasnim »

You need to use https://bryntum.com/docs/gantt/api/Gantt/feature/CellEdit#event-beforeCellEditStart.

Here is an example of how you can achieve it:

listeners : {
	 beforeCellEditStart() {
	 	if (parentTask) {
	 		return false;
	 	}
	 }
}

Post by shimnx »

  beforeCellEditStart({ editorContext }) {
                const { column, record } = editorContext;
                console.log(column, record)
              
if (column.type === 'resourceassignment' && record.originalData.children) { // prevent editing percentdone return false; } },

This is my current code, but when I create a new task and add subtasks to it, the task still assigns people


Post by tasnim »

Try this :

beforeCellEditStart({ editorContext }) {
	const { column, record } = editorContext;
	
if (column.type === 'resourceassignment' && record.isParent) {
	return false;
}
}

Post by shimnx »

Thank you. In addition, I have another question, how can I monitor the event of adding Subtask? I want to monitor whether there is an allocator in the event of changing task, if there is an allocator, the Subtask is not allowed to be added


Post by tasnim »

Could you please explain with some images by annotating, what exactly you want to achieve?


Post by shimnx »

I want to listen for the 'add subTask' event, in this event to determine whether the current task has assigned a person, if so, 'subTask' is not allowed to be added.

Attachments
屏幕截图 2022-07-19 121849.png
屏幕截图 2022-07-19 121849.png (28.27 KiB) Viewed 770 times

Post by tasnim »

You need to override the addSubtask function in Gantt.

Here is how you can override it:

class MyGantt extends Gantt {
    addSubtask(taskRecord) {
        // if the task is not assigned to a person then add the subtask
        if (!taskRecord.resources.length) {
            const result = this.addTask(taskRecord, { asChild : true });

        this.toggleCollapse(taskRecord, false);
        return result;
    }
}
}

Then use the customized MyGantt instead of Gantt

new MyGantt({ ... });

Post by shimnx »

Please check my code, I wrote this method but it doesn't seem to trigger

Attachments
advanced examples 3.zip
(165.76 KiB) Downloaded 30 times

Post by tasnim »

Oh, if you're using angular then don't use that. You should use the taskMenu feature for this.

Please check docs : https://bryntum.com/docs/gantt/api/Gantt/feature/TaskMenu

Here is how you can achieve it :

taskMenu : {
            items : {
                add : {
                    menu : {
                        subtask : {
                            onItem : ({ taskRecord }) => {
                                if (!taskRecord.resources.length) {
                                    const result = gantt.addTask(taskRecord, { asChild : true });

                                gantt.toggleCollapse(taskRecord, false);
                                return result;
                            }
                        }
                    }
                }
            }
        }
    },

Post Reply