Sorting Tasks by Column in Gantt Chart
Contents
[
Hide
Show
]Aspose.Tasks for Java provides the ability to sort tasks by any column in the Gantt chart view. This is accomplished with the help of the comparer method saveOptions.setTasksComparer before rendering in Gantt chart. The default comparer sorts tasks by task ID if no other option is specified.
Sort Tasks
1Project project = new Project();
2
3project.addTask("B Task 1");
4
5project.addTask("A Task 2");
6
7SaveOptions options = new PdfSaveOptions();
8
9BarStyle barStyle = new BarStyle();
10
11barStyle.setBarTextConverter(new BarStyle.TaskToBarTextConverter() {
12
13 //@Override
14
15 public String invoke(Task task) { return task.getName(); }
16
17} );
18
19barStyle.setBarColor(java.awt.Color.BLUE);
20
21List<BarStyle> styles = new LinkedList<BarStyle>();
22
23styles.add(barStyle);
24
25options.setBarStyles(styles);
26
27options.setTasksComparer(new TaskNameComparator());
28
29project.save("output.pdf", options);
30
31
32
33// ...
34
35
36
37private static class TaskNameComparator implements Comparator<Task>
38
39{
40
41 //@Override
42
43 public int compare(Task o1, Task o2) {
44
45 return o1.getName().compareTo(o2.getName());
46
47 }
48
49}