Skip to content

Commit 69160b8

Browse files
author
alex
committed
Merge pull request '[add] a section on sorting by several fields' (#110) from add-sort-function-example-GS-2902 into master
Reviewed-on: https://git.webix.io/Servers/gantt-docs/pulls/110 Reviewed-by: alex <[email protected]>
2 parents 6be2de0 + f5fd5e7 commit 69160b8

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

data/desktop/sorting.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff 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
123122
gantt.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+

0 commit comments

Comments
 (0)