Our state of the art Gantt chart


Post by harshalkhode1703 »

Hi,
I am using bryntum gantt,
When I right click the menu open for some operations like: add, delete the task.
i click on add data

and i am trying to fetch it in ----- onBeforeTaskAdd method.

when i console the whole data like

const addTaskFunc = async (data: any) => {
    console.log(data.taskRecord._data);
    }

the method returns the output looks like.

Screenshot from 2023-03-15 10-36-05.png
Screenshot from 2023-03-15 10-36-05.png (94.44 KiB) Viewed 180 times

so i the data is inside the _data parameter of the object, which we can see acc. to the image.
but when i try to console like.

const addTaskFunc = async (data: any) => {
    console.log(data.taskRecord._data.parentId);
    }

it gives me undefined.

I want to fetch parameters from _data
please let me know what mistake i am doing.

or if there is any other approch to fetch data when adding new task?


Post by tasnim »

Hi,

_data is not public property. We don't recommend our users use properties that are not available in docs.
And the parentId will be undefined because you're listening to beforeTaskAdd, so it's not added to the store. So that's why you're getting undefined.

Good Luck :),
Tasnim


Post by harshalkhode1703 »

So where to fire backend api for
add task and delete task when i click in Context menu.
what method i need to use?


Post by tasnim »

I think this is what you're looking for https://bryntum.com/products/gantt/docs/api/Gantt/data/TaskStore#event-add
This will fire, every time you add a task to taskStore

Please check the whole list of events in the task store https://bryntum.com/products/gantt/docs/api/Gantt/data/TaskStore#events


Post by harshalkhode1703 »

I added it in taskStore as you suggested

listeners: {
              add: (data: any) => {
                console.log(data);
                addTaskFunc(data);
              },

why it is running multiple time.
sometimes 3 time, sometimes more.

also
its behaviour is not as expected.
when a add taskstore it also disables the row selection
and chart gets invisible
may be i am making any mistake

the code is this:

<BryntumGantt
    height={props.height}
    ref={props.ganttRef}
    {...props.ganttConfig}
    tasks={props.tasks}
    onFinishCellEdit={props.onFinishCellEdit}
    onTaskDrop={props.onTaskDrop}
    onTaskResizeEnd={props.onTaskResizeEnd}
    onAfterTaskEdit={props.onTaskEdit}
    onBeforeTaskAdd={props.onAddTask}
    onSelectionChange={props.onSelectTask}
    taskStore={{
            WbsMode: "auto",
            listeners: {
              remove: (data:any) => {
                setDeleteModalOpen(true);
              },
            },
          }}
  /> 

please provide suggestion faster.
and most importantly react specific example for managing events.

the doc is bit confusing :
i am not getting where to add all the things.


Post by tasnim »

Hi,

Yes. because there are some other actions that happen when you add like a subtask it fires 2 times.
The first one is that this is added to the store. and second one is that the setting of the parent expanded.
But you're saying sometimes it fires 3 or more times, there might be this kind of stuff. But can't say without reproducing.

What are the things that need to be done to fire it 3 or more times?


Post Reply