search envelope-o feed check
Home Unanswered Active Tags New Question
user comment-o

Does Gantt have a dispose() method?

Asked by Ethan
1 year ago.

Hi team,

I am doing a Gantt chart for jobs.
I would like to display a Gantt chart for jobs that I selected.
I use Axios send and receive data from database.
It is ok for the first Gantt chart, but when come to the second one, it failed due to the error:
"The target placeholder was already initialized by another DayPilot component instance."
I know Scheduler has dispose() method, does Gantt has something similar with it?

Thank you very much!

Comment posted by Ethan
1 year ago.

I think I just found a way like the codes below:

const Form = () => {
    const [dpg, setDpg] = React.useState(new DayPilot.Gantt("dp"));

    React.useEffect(() => {
        dpg.init();
    }

    const updateGantt = () => {
        axios.post('./src/GanttChart/getData/ganttData.php', {
            jobNumber: jobNumber,
        })
            .then(function (response) {
                console.log(response.data);
                dpg.startDate = "2023-01-01";
                dpg.days = 30;
                dpg.tasks.list = [
                    { id: 1, start: "2023-01-05T00:00:00", end: "2023-01-10T15:00:00", text: jobNumber }
                ];
                dpg.update();
            })
            .catch(function (error) {
                console.log(error);
            });
    }
}

Lol, Nice! I can continue now!

Comment posted by Ethan
1 year ago.

Sorry, the useEffect hook was wrong, should be this one, the code above just an example~

React.useEffect(() => {
dpg.init();
}, [])
Answer posted by Dan Letecky [DayPilot]
1 year ago.

There is a special React package that defines a <DayPilotGantt> React component which you can use in your JSX instead of creating the instance manually using a placeholder and init() method.

To see how to use the React Gantt chart component, please see the following tutorial:
https://code.daypilot.org/35516/react-gantt-chart-tutorial

The dispose methods is also available (now it's added to the API docs):
https://api.daypilot.org/daypilot-gantt-dispose/

Comment posted by Ethan
1 year ago.

Thank you very much for your help!
The old app I am maintaining was not created by "npx create-react-app xxx" :(
I only added React for the new page of the app.
Using "import {DayPilotGantt} from "daypilot-pro-react"; does not work, and I have not found a proper way to make it work (just started learning React), maybe I need to config webpack myself?
So that why I created the instance manually.
Thank you again for your help ;)

This question is more than 1 months old and has been closed. Please create a new question if you have anything to add.