Our state of the art Gantt chart


Post by sanjeeva »

Product: bryntum/gantt-trial@4.2.4

How to set default startDate and endDate while adding tasks. our requirement is that we want to set the default value null. I tried to set values in "beforeadd" event but had no success.


Post by mats »

How to set default startDate and endDate while adding tasks

How do you add your tasks? Context menu or you have a button outside the Gantt?


Post by sanjeeva »

I add task using Context menu.


Post by alex.l »

If we are talking about addTaskAbove/addTaskBelow, here is docs for this feature https://bryntum.com/docs/gantt/#Gantt/feature/TaskMenu
Menu items you need are add> addTaskAbove and add> addTaskBelow
By default it just copies data from referral task, but you may apply your changes like this:

features : {
        taskMenu : {
            // Extra items for all events
            items : {
                add: {
                    menu : {
                        addTaskAbove : {
                            onItem: async ({taskRecord}) => {
                                const task = await gantt.addTaskAbove(taskRecord);
                                task.name = 'test'; // or whatever you need
                                gantt.project.commitAsync();
                            }
                        }
                    }
                }
            }
        }
}

All the best,
Alex


Post by sanjeeva »

How to import gantt in AppConfig.js
because const task = await gantt.addTaskAbove(taskRecord); and gantt.project.commitAsync(); gives error


Post by mats »

because const task = await gantt.addTaskAbove(taskRecord); and gantt.project.commitAsync(); gives error

Please always attach error messages.


Post by sanjeeva »

I get the following error. i have attached my AppConfig file for your reference.

Uncaught (in promise) ReferenceError: gantt is not defined
    at MenuItem.onItem (AppConfig.js:162)
    at MenuItem.callback (gantt.module.js:515)
    at MenuItem.trigger (gantt.module.js:515)
    at MenuItem.doAction (gantt.module.js:515)
    at Menu.triggerElement (gantt.module.js:515)
    at Menu.onMouseClick (gantt.module.js:515)
    at HTMLDivElement._0x259e8d (gantt.module.js:515)
    at HTMLDivElement.o (LogRocket.min.js:2)
Attachments
AppConfig.js
(4.17 KiB) Downloaded 48 times

Post by alex.l »

gantt in the code snippet above is a variable with the Gantt instance. In case you import AppConfig into the file where you create a gantt instance, better might be to move this method declaration to the place where it's more obvious to you how to get a link to the Gantt instance.

All the best,
Alex


Post by sanjeeva »

Actually I am using your provided vue wrapper sample. Can you tell me how to declare addTaskAbove and addTaskBelow events to the following gantt object.

const gantt = this.$refs.gantt.instance;

Post by saki »

Actually, you get reference to the owning gantt in the onItem listener. This should work for you:

    taskMenuFeature: {
        // Extra items for all events
        items: {
            add: {
                menu: {
                    addTaskAbove: {
                        onItem: async ({source:gantt, taskRecord}) => {
                            const task = await gantt.addTaskAbove(taskRecord);
                            task.name = 'test'; // or whatever you need
                            gantt.project.commitAsync();
                        }
                    },
                    addTaskBelow: {
                        onItem: async ({source:gantt, taskRecord}) => {
                            const task = await gantt.addTaskBelow(taskRecord);
                            task.name = 'test'; // or whatever you need
                            gantt.project.commitAsync();
                        }
                    }
                }
            }
        }
    },

Mind also the name - we suffix feature names with Feature word in Vue.


Post Reply