My gantt is populating data from a Nested API JSON file. It works almost perfectly but it won’t display the data if a previous data have been assign to a task with similar name in the task field, but it’s not an issue for any other field. Preferably I want all the task to be the child of assign_to field but I dont know how to do it when loading the data using gantt.config.columns
Below is my code, any help is much appreciated
HTML
<div id="my_scheduler" style='width:1585px; height:325px;'></div>
javascript
[code]function prepareData(rawData){
var ganttData = { data: [], links: []};
for(var i = 0; i < rawData.data.length; i++){
var task = {}
gantt.mixin(task, rawData.data[i]);
gantt.mixin(task, rawData.data[i].task);
task.text = task.name;
ganttData.data.push(task);
}
return ganttData;
}
gantt.config.columns = [
{name: “official_name”, align: “left”, template: function(data){
if(data.assign_to) return data.assign_to.official_name;
}, label: “Assign To”, tree:true, width: 200},
{name: “text”, label: “Task”, align: “left”, hide:true, width: 100},
{name: “start_date”, width: 90},
{name: “end_date”, align: “left”, label: “End Date”, width: 90},
{name: “duration”, width: 50}
];
gantt.config.xml_date = “%Y-%m-%d”;
function initializeGantt(content_id) {
scheduler = gantt.init(“my_scheduler”, new Date(‘2017, 01, 01’), new Date(‘2017, 12, 31’));
data = localStorage.getItem(“id”);
$.get("/dashboard/ganttchart_list/"+data+"/?format=json", function(result) { gantt.parse(prepareData(result)); });[/code]
API
{
"data": [
{
"assign_to": {
"id": 3,
"employee_id": "28141",
"official_name": "Hal Jordan",
},
"task": {
"id": 1,
"name": "Modeling",
"description": "3d modeling work"
},
"start_date": "2017-06-15",
"end_date": "2017-06-19"
},
{
"assign_to": {
"id": 3,
"employee_id": "28144",
"official_name": "Kyle Rayner",
},
"task": {
"id": 8,
"name": "Composting",
"description": null
},
"start_date": "2017-06-01",
"end_date": "2017-06-08"
},
{
"assign_to": {
"id": 2,
"employee_id": "28142",
"official_name": "John Stewart",
},
"task": {
"id": 8,
"name": "Modelling",
"description": null
},
"start_date": "2017-06-22",
"end_date": "2017-06-25"
}
]
}