а

Gantt multiple resources Assigning with histogram


#1

Hi,

Now i am customizing gantt with resource histogram using https://docs.dhtmlx.com/gantt/samples/11_resources/09_resource_histogram.html
example. Am facing a issue in constructing json using php gantt connector .
in Loghtbox
{ name: “owner”, type: “resources”, map_to: “owner”, options: gantt.serverList(“people”), default_value:WORK_DAY, unassigned_value: UNASSIGNED_ID},

In Task Table owner field Data Type : TEXT In this field data stored like this [{“resource_id”: “6”," value": “5”}]
In gantt.load (load.php)
In browser console :
“data”: [
{ “id”: 1, “text”: “Office itinerancy”, “type”: “project”, “start_date”: “02-04-2019 00:00”, “duration”: 17, “progress”: 0.4, “owner”: " [{“resource_id”:“5”, “value”: 3}] " , “parent”: 0},
]
}

Instead of

“data”: [
{ “id”: 1, “text”: “Office itinerancy”, “type”: “project”, “start_date”: “02-04-2019 00:00”, “duration”: 17, “progress”: 0.4, “owner”: [{“resource_id”:“5”, “value”: 3}] , “parent”: 0},
]
}

load.php

include (‘codebase/connector/gantt_connector.php’);

$res = new PDO(“mysql:host=localhost;dbname=gantt”, “root”, “”);

$gantt = new JSONGanttConnector($res);
$gantt->render_links(“gantt_links”,“id”,“source,target,type”);
$gantt->render_table(
“gantt_tasks”,
“id”,
“start_date,duration,text,type,owner,progress,sortorder,parent”
);

owner getting as string instead of object. How do i fix this ?


#2

Hello Janani,
In our samples, the values for the owner property are stored as an array, not as a string:
https://docs.dhtmlx.com/gantt/samples/common/resource_project_assignments.json
And you store the owner parameter as a string:

In Task Table owner field Data Type : TEXT In this field data stored like this [{“resource_id”: “6”," value": “5”}]

If I remember correctly, it is easier to create a different table and connect several tables, than to implement a solution to store arrays:

However, you can still store the arrays as strings, but you need to parse them after loading tasks.
To do that, you need to use the eachTask method:

gantt.eachTask(function(task){
  if (task.owner && typeof task.owner == 'string') {
    task.owner = eval(task.owner);
    gantt.updateTask(task.id);
  }
})

https://docs.dhtmlx.com/gantt/api__gantt_eachtask.html
Here is an example of how it works:
http://snippet.dhtmlx.com/8baaebb6e


#3

You must be very careful while applying any solution because sometimes
many forum members are not able to answer the question but still they
answer it anyhow. So, It’s important to confirm the solution and then apply it.