Change parent

Is it possible to change the parent of a task once it is on the gantt chart. ie by dragging up or down in the grid or or manually reassigning the parent.

Hello,
it can be reassigned only programmatically, you’ll need to assign new value to the ‘parent’ property of the task and then refresh the ganttvar task = gantt.getTask(task_id); task.parent = new_parent_id; gantt.render();

Is it possible to use a code in the lightbox to change the parent?
It will be great to have a list like this:

gantt.config.lightbox.sections = [ {name: "parent", height: 22, map_to: "parent", type: "select", options: here a connection to id for key and text for label from the gantt_tasks table} ];
How can we implement that?

Here is a solution inspired by this example:
http://docs.dhtmlx.com/scheduler/samples/01_initialization_loading/11_connector_options_json.html

{name: "parent", height: 22, map_to: "parent", type: "select", options:gantt.serverList("parent")},

In connector.php, I have this:

<?php include ('config.php'); $list = new JSONOptionsConnector($res, $dbtype); $list->render_table("gantt_tasks","id","id(value),text(label)"); $gantt = new JSONGanttConnector($res, $dbtype); $gantt->mix("open", 1); //$gantt->enable_order("sortorder"); $gantt->set_options("parent", $list); $gantt->render_links("gantt_links", "id", "source,target,type"); $gantt->render_table("gantt_tasks","id","start_date,end_date,text,duration,progress,sortorder,owner,conge,parent",""); ?>
This is very limited because each time I add a task, I have to reload my page to update the list of parent. It’s dangerous because I can make some mistakes like putting the same id in parent like in id (I have tried it’s bugging). Finally, it’s missing the level 0 (maybe we can add it somehow).

It is an interesting idea.
We will add it as possible improvment for the next version.

I have tried to implement the level 0.
I need some help concerning adding an entry to the serverList.
I checked this doc:
http://docs.dhtmlx.com/scheduler/api__scheduler_serverlist.html
I added to my code this

var parent_array=new Array;
parent_array.push({key:"0",label:" "});
...
{name: "parent", height: 22, map_to: "parent", type: "select", options:gantt.serverList("parent",parent_array)},

It doesn’t add it to my list.

I have found an example for adding an entry to serverList there:
http://forum.dhtmlx.com/viewtopic.php?f=6&t=31273&p=98127&hilit=serverList#p98127
Unfortunately updateCollection is not implemented in dhtmlxGantt.
Do you plan to implement it or can I found another solution?

Yep, will be added in the next build, as for now you can use code like next
You can use code like next

gantt.updateCollection = function(list_name, collection) { var list = scheduler.serverList(list_name); if (!list) return false; list.splice(0, list.length); list.push.apply(list, collection || []); gantt.resetLightbox(); };

Thanks Stanislav. It’s working.
Here is a completed solution with level 0 :

gantt.updateCollection = function(list_name, collection) {
	var list = gantt.serverList(list_name);                 
	if (!list) return false;                                
	list.splice(0, list.length);                            
	list.push.apply(list, collection || []);                
	gantt.callEvent("onOptionsLoad", []);                   
	gantt.resetLightbox();                                  
	return true;                                            
};
...
gantt.locale.labels["section_parent"] = "Parent";
gantt.config.lightbox.sections = [
{name: "parent", height: 22, map_to: "parent", type: "select", options:gantt.serverList("parent")},
...
gantt.attachEvent("onLoadEnd", function(){                         
	var items = gantt.serverList("parent").slice();//copy sections 
	items.unshift({key:0, label:" "});//insert first section       
	gantt.updateCollection("parent", items);//update list          
});                                                                                                                        

I have a last inquiry it’s about the reloading of parent in the lightbox.
I have tried something like this:
http://forum.dhtmlx.com/viewtopic.php?f=6&t=16259&p=49982&hilit=afterupdate+reload+page#p49982
with this code:

dp.attachEvent("onAfterUpdate", function(){ gantt.load("../common/connector.php"); //the same data feed as was used for initial data loading return true; });
When I add a new task it’s bugging (the lightbox doesn’t appear) and I have multiple default tasks generated.
I would like to update the options in the select of my parent each time I add a new task.
Could you help, please?

You can try to use

dp.attachEvent("onAfterUpdate", function(){ gantt.clearAll(); gantt.load("../common/connector.php"); return true; });

Anyway it looks as kind of expensive solution. Instead of it, you can build the new array of options on client side

You can use eachTask command to iterate through all tasks
docs.dhtmlx.com/gantt/api__gantt_eachtask.html
Based on task’s data you can build new array of options and use gantt.updateCollection to refresh list of options in the lightbox.