Integarting gantt in php application

Hi ,

Can anyone help me what is database structure for gantt with resources. How I will get the resources from database instead of

resourcesStore.parse([
{id: 1, text: “QA”, parent:null},
{id: 2, text: “Development”, parent:null},
{id: 3, text: “Sales”, parent:null},
{id: 4, text: “Other”, parent:null},
{id: 5, text: “Unassigned”, parent:4},
{id: 6, text: “John”, parent:1, unit: “hours/day” },
{id: 7, text: “Mike”, parent:2, unit: “hours/day” },
{id: 8, text: “Anna”, parent:2, unit: “hours/day” },
{id: 9, text: “Bill”, parent:3, unit: “hours/day” },
{id: 10, text: “Floe”, parent:3, unit: “hours/day” }
]);

how I will store the newly created task into database

Hello Sravanthi,
Gantt doesn’t save the resource data into a database. You need to implement a custom solution if you want to do that.
Here is the snippet where Gantt saves the resource data as JSON data:
https://snippet.dhtmlx.com/7d2c70130

If you just need to save resource names like you listed, you need to create a table with the following fields:

CREATE TABLE `resource_data` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `text` varchar(255) NOT NULL,
  `parent` int(11) NOT NULL,
  `unit` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
);

Then you need to load the data from that table into a variable and call resourcesStore.parse(your_variable).
Unfortunately, I don’t have a ready demo.

how I will store the newly created task into database

Usually, new tasks are saved automatically, if you follow this guide:
https://docs.dhtmlx.com/gantt/desktop__howtostart_php.html#step3configuringadatabase

Hello ramil,

Same thing am facing … i created database table for resources. i want to know how to load the data from that table into a variable using php . please guide me for this
resourcesStore.parse(your_variable)
or
gantt.$resourcesStore.parse(your_variable)

its for group level. i created table name as gantt_emp and emp.php in this file fetch emp details from db and echo json_encode($res);

in front end
using gantt.load (emp.php);
it throw error. please help.

Hello Janani,

i created database table for resources. i want to know how to load the data from that table into a variable using php . please guide me for this

Unfortunately, I don’t specialize in PHP, so I won’t be able to suggest to you how to load the data from the server-side to a JSON variable.


its for group level. i created table name as gantt_emp and emp.php in this file fetch emp details from db and echo json_encode($res);
in front end
using gantt.load (emp.php);
it throw error.

You need to load the resource data with the resourcesStore.parse(your_variable) command. You cannot load it another way.
If you want to load the gantt data altogether with the resource data, you need to put the resource data into a collection:
https://docs.dhtmlx.com/gantt/desktop__supported_data_formats.html#jsonwithcollections
To make it work correctly, first, you need to create a collection with that name, then load the data.

When you use the gantt.load() and gantt.parse() commands, Gantt expects to load tasks and links, then additional properties. If you try parsing only the additional properties, it won’t work. In that case, you need to specify the data and links without objects, for example:

gantt.serverList("resource_data"); 
gantt.parse({
  "data": [],
  "links": [],
  "collections": {
    "resource_data":[
      {id: 1, text: "QA", parent:null},
      {id: 2, text: "Development", parent:null},
      {id: 3, text: "Sales", parent:null},
      {id: 4, text: "Other", parent:null},
      {id: 5, text: "Unassigned", parent:4},
      {id: 6, text: "John", parent:1},
      {id: 7, text: "Mike", parent:2},
      {id: 8, text: "Anna", parent:2},
      {id: 9, text: "Bill", parent:3},
      {id: 10, text: "Floe", parent:3}
    ]
  }
})

However, you still need to use the resourcesStore.parse() command to load the resource data, although, now you can use the collections:

resourcesStore.parse(gantt.serverList("resource_data"));

Here is the snippet that demonstrates how it works:
http://snippet.dhtmlx.com/b21bb6b28