File tree Expand file tree Collapse file tree 1 file changed +31
-2
lines changed
Expand file tree Collapse file tree 1 file changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -116,9 +116,38 @@ A custom sorting function is called for a pair of task objects (a and b) and ret
116116- ** 0** - the order of both objects doesn't change.
117117
118118
119- 3 ) sorting a column according to the values of a different field of the task by
120- setting * sort* to that field
119+ 3 ) sorting a column according to the values of a different field of the task by setting * sort* to that field
121120
122121~~~ js
123122gantt .config .columns [1 ].sort = ' other_field' ;
124123~~~
124+
125+
126+ Sorting by several fields
127+ ---------------------
128+
129+ You can sort the grid of the Gantt chart by several properties (fields) by using a custom sorting function.
130+ In the following example, data is sorted by the * duration* and * priority* fields:
131+
132+ ~~~ js
133+ let sortDirection = - 1
134+ function customSort () {
135+ sortDirection *= - 1 ;
136+ gantt .sort (function (task1 , task2 ) {
137+ // sort by priority
138+ if (task1 .duration == task2 .duration ) {
139+ return (task1 .priority - task2 .priority ) * sortDirection
140+ }
141+ // sort by duration
142+ return (task1 .duration - task2 .duration ) * sortDirection
143+ });
144+ }
145+ ~~~
146+
147+ {{editor https://snippet.dhtmlx.com/upu86azw Sort by several properties (fields) with a custom sort function}}
148+
149+ - In case the duration of the tasks is the same, sorting by this field isn't applied, and the tasks are sorted by the * priority* field.
150+ - If the duration of the tasks is different, the grid will be sorted by the * duration* property.
151+
152+
153+
You can’t perform that action at this time.
0 commit comments