Sort 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();
 2project.addTask("B Task 1");
 3project.addTask("A Task 2");
 4SaveOptions options = new PdfSaveOptions();
 5BarStyle barStyle = new BarStyle();
 6barStyle.setBarTextConverter(new BarStyle.TaskToBarTextConverter() {
 7    //@Override
 8    public String invoke(Task task) { return task.getName(); }
 9} );
10barStyle.setBarColor(java.awt.Color.BLUE);
11List<BarStyle> styles = new LinkedList<BarStyle>();
12styles.add(barStyle);
13options.setBarStyles(styles);
14options.setTasksComparer(new TaskNameComparator());
15project.save("output.pdf", options);
16
17// ...
18
19private static class TaskNameComparator implements Comparator<Task>
20{
21    //@Override
22    public int compare(Task o1, Task o2) {
23        return o1.getName().compareTo(o2.getName());
24    }
25}
Subscribe to Aspose Product Updates

Get monthly newsletters & offers directly delivered to your mailbox.