How to store task order position in Rails application?


We need manual reorder tasks on a list feature. When I setup Gantt like this

gantt.config.order_branch = true

then I can reorder tasks by drag and drop them on the list. Ajax API sends @gantt_mode = ‘order’ .

How can I store/recive tasks new locations on that list, not just @gantt_mode ?

Cheers, Szymon

The data re-ordering call contains “target” parameter that point to the id of item on which place task was moved.

Check … deroftasks


  1. I begin with something like this

gantt.config.xml_date = "%Y-%m-%d %H:%i:%s"; gantt.config.order_branch = true; gantt.init("gantt_here"); gantt.load("<%= data_gantts_path %>", "json"); var dp = new dataProcessor("<%= db_action_gantts_path %>"); dp.init(gantt);

What is the attribute name to map a task orrder when setup JSON data initally? Because sortorder with values like 1,2,3 doesn’t work with above setup.

  1. When I reaorder by drag and drop I do have target parameter which I can use. I noticed 2 cases. First when it points to the id of item on which place task was moved. Second, if I put task on the end of the list then I have “next: id_of_last_task” as a target value. Are these all syntax cases in target field when call ‘reorder’ ?

Cheers, Szymon

The full integration will work only if you are using connectors on server side, as client side doesn’t use the sortorder field. This field is used for data sorting on server side during data loading and updated when “order” command send to server side.

Hi @stanislav,

Considering the following guide of yours what is wrong with above setup?

Best Regards,

Storing sort order is a bit tricky.

Client side do not change this field during data reordering, instead of it dataprocessor sends an extra request to server side, with info about moved row id and new position. It expects that server side code will update sortorder field in necessary way.

You can add when "order" section to the db_action and place the logic there. It will require few DB queries.

  • get sortorder of source row
  • get sortorder of target row
  • update sortorder for all involved rows

Also you will need to set sortorder in the database for newly created records.

Hi @Stanislav,

I did that.
But still, if table gantt_tasks looks like this:
– record 1
name: ‘task1’
sortorder: 3
– record 2
name: ‘task2’
sortorder: 2
– record 3
name: ‘task3’
sortorder: 1
Gantt (basic licence) doesn’t sort it out with my inital setup. I use the following instruction of yours … ganttchart . You can see that there is sortorder field in your gantt_tasks table but when you setup it then it does not work out.


When you are using connector it adds “sort by sortorder” to the SQL query.
If you are using custom backend, you need to apply such kind of initial sorting as well.