dhtmlxGantt 2.0 Branch ordering with drag and drog

I would like to be able to change the order of the tasks.
I have tried to use branch ordering like in this example:
http://docs.dhtmlx.com/gantt/samples/07_grid/02_branch_ordering.html
with this code:

gantt.config.order_branch = true;

First, I can’t use sorting with branch ordering:

gantt.config.sort = true;

When I move a task, unfortunately it doesn’t update the parent in my database.
When I reload my page the previous order is loaded.

Sorting and manual ordering are mutual exclusive. This is expected.

As for storing in DB.

  • be sure that you have sortorder field in the database
  • add in connector’s file the next line ( it is commented in the sample connector files )
    $gantt->enable_order(“sortorder”);
  • be sure that all initial records has some non null values for sortorder

I did exactly like you said, here is my connector file:

[code]<?php

include (‘config.php’);

$gantt = new JSONGanttConnector($res, $dbtype);

$gantt->mix(“open”, 1);
$gantt->enable_order(“sortorder”);

$gantt->render_links(“gantt_links”, “id”, “source,target,type”);
$gantt->render_table(“gantt_tasks”,“id”,“start_date,end_date,text,sortorder,duration,progress,owner,conge,parent”,"");

?>[/code]
Every time I add a task, it adds another default task with it. I can see it when I reload the page and in my database.
How does the sortorder field work? Is it like a level id for the tree ?

Sortorder is integer value which defines position of item ( small values at top of list, big values at end of list ). Sortorder value is defined for all items globally ( it doesn’t related to the level in hierarchy )

When you have enable_order in the php code, connector will do 2 extra tasks

  • set sortorder value for newly created tasks
  • will change sortorder value after drag-n-drop operations on a client side

If it doesn’t work correctly, please enable php logging and provide the content of a log file.

docs.dhtmlx.com/doku.php?id=dhtm … tor:errors

Thanks for your answer.
Here is a log of the test I have just done


====================================
Log started, 28/10/2013 09:55:43
====================================

SELECT `id`,`start_date`,`end_date`,`text`,`duration`,`progress`,`sortorder`,`owner`,`conge`,`parent` FROM gantt_tasks ORDER BY sortorder

SELECT `id`,`source`,`target`,`type` FROM gantt_links

Done in 0.031241893768311s



====================================
Log started, 28/10/2013 09:55:47
====================================

DataProcessor object initialized
1382954147351_text => Activité
1382954147351_start_date => 2013-10-15 01:00:00
1382954147351_duration => 4
1382954147351_progress => 0.25
1382954147351_parent => 89
1382954147351_id => 1382954147351
1382954147351_end_date => 2013-10-19 01:00:00
1382954147351_!nativeeditor_status => inserted
ids => 1382954147351

Row data [1382954147351]
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: owner

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: owner

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: conge

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

Incorrect field name used: conge

data
text => Activité
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
!nativeeditor_status => inserted

INSERT INTO gantt_tasks(`start_date`,`end_date`,`text`,`duration`,`progress`,`sortorder`,`owner`,`conge`,`parent`) VALUES ('2013-10-15 01:00:00','2013-10-19 01:00:00','Activité','4','0.25','','','','89')

SELECT MAX(sortorder) as maxvalue FROM gantt_tasks

exception 'Exception' with message 'MySQL operation failed
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxvalue FROM gantt_tasks' at line 1' in E:\wamp\www\gantt\codebase\connector\db_common.php:1085
Stack trace:
#0 E:\wamp\www\gantt\codebase\connector\db_common.php(747): MySQLDBDataWrapper->query('SELECT MAX(sort...')
#1 E:\wamp\www\gantt\codebase\connector\db_common.php(659): DBDataWrapper->queryOne('SELECT MAX(sort...')
#2 E:\wamp\www\gantt\codebase\connector\dataprocessor.php(170): DBDataWrapper->new_record_order(Object(DataAction), Object(DataRequestConfig))
#3 E:\wamp\www\gantt\codebase\connector\dataprocessor.php(97): DataProcessor->inner_process(Object(DataAction))
#4 E:\wamp\www\gantt\codebase\connector\base_connector.php(491): DataProcessor->process(Object(DataConfig), Object(DataRequestConfig))
#5 E:\wamp\www\gantt\codebase\connector\gantt_connector.php(128): Connector->render()
#6 E:\wamp\www\gantt\codebase\connector\base_connector.php(410): GanttConnector->render()
#7 E:\wamp\www\gantt\samples\common\connector.php(10): Connector->render_table('gantt_tasks', 'id', 'start_date,end_...', '')
#8 {main}

Edit operation finished
0 => action:error; sid:1382954147351; tid:91;

Done in 0.062484979629517s



====================================
Log started, 28/10/2013 09:56:13
====================================

DataProcessor object initialized
1382954147351_text => test with branch ordering
1382954147351_start_date => 2013-10-15 01:00:00
1382954147351_duration => 4
1382954147351_progress => 0.25
1382954147351_parent => 89
1382954147351_id => 1382954147351
1382954147351_end_date => 2013-10-19 01:00:00
1382954147351_owner => 0
1382954147351_conge => 0
1382954147351_!nativeeditor_status => inserted
ids => 1382954147351

Row data [1382954147351]
text => test with branch ordering
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
owner => 0
conge => 0
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
text => test with branch ordering
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
owner => 0
conge => 0
!nativeeditor_status => inserted

Incorrect field name used: sortorder

data
text => test with branch ordering
start_date => 2013-10-15 01:00:00
duration => 4
progress => 0.25
parent => 89
id => 1382954147351
end_date => 2013-10-19 01:00:00
owner => 0
conge => 0
!nativeeditor_status => inserted

INSERT INTO gantt_tasks(`start_date`,`end_date`,`text`,`duration`,`progress`,`sortorder`,`owner`,`conge`,`parent`) VALUES ('2013-10-15 01:00:00','2013-10-19 01:00:00','test with branch ordering','4','0.25','','0','0','89')

SELECT MAX(sortorder) as maxvalue FROM gantt_tasks

exception 'Exception' with message 'MySQL operation failed
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'maxvalue FROM gantt_tasks' at line 1' in E:\wamp\www\gantt\codebase\connector\db_common.php:1085
Stack trace:
#0 E:\wamp\www\gantt\codebase\connector\db_common.php(747): MySQLDBDataWrapper->query('SELECT MAX(sort...')
#1 E:\wamp\www\gantt\codebase\connector\db_common.php(659): DBDataWrapper->queryOne('SELECT MAX(sort...')
#2 E:\wamp\www\gantt\codebase\connector\dataprocessor.php(170): DBDataWrapper->new_record_order(Object(DataAction), Object(DataRequestConfig))
#3 E:\wamp\www\gantt\codebase\connector\dataprocessor.php(97): DataProcessor->inner_process(Object(DataAction))
#4 E:\wamp\www\gantt\codebase\connector\base_connector.php(491): DataProcessor->process(Object(DataConfig), Object(DataRequestConfig))
#5 E:\wamp\www\gantt\codebase\connector\gantt_connector.php(128): Connector->render()
#6 E:\wamp\www\gantt\codebase\connector\base_connector.php(410): GanttConnector->render()
#7 E:\wamp\www\gantt\samples\common\connector.php(10): Connector->render_table('gantt_tasks', 'id', 'start_date,end_...', '')
#8 {main}

Edit operation finished
0 => action:error; sid:1382954147351; tid:92;

Done in 0.046864032745361s



====================================
Log started, 28/10/2013 09:56:16
====================================

SELECT `id`,`start_date`,`end_date`,`text`,`duration`,`progress`,`sortorder`,`owner`,`conge`,`parent` FROM gantt_tasks ORDER BY sortorder

SELECT `id`,`source`,`target`,`type` FROM gantt_links

Done in 0.015621185302734s

Please try to update php files of connector with attached ones.
codebase.connector.php.zip (72 KB)