GWT 2.5 を使用して、並べ替え可能な日付列を持つ CellTable を作成しています。
私のコードは次のとおりです。
CellTable<Activity> table = new CellTable<Activity>();
table.setRowStyles(new RowStyles<Activity>() {
@Override
public String getStyleNames(Activity row, int rowIndex) {
return TABLE_ROW_STYLE_NAME;
}
});
// create date column
TextColumn<Activity> dateColumn = new TextColumn<Activity>() {
@Override
public String getValue(Activity a) {
return dateFormat.format(a.getDate());
}
};
dateColumn.setSortable(true);
dateColumn.setDefaultSortAscending(false);
// add column to table
table.addColumn(dateColumn, myConstants.dateColumnHeader());
// attach provider to table
activityProvider.addDataDisplay(table);
// create sort handler
ListHandler<Activity> sortHandler = new ListHandler<Activity>(activityProvider.getList());
sortHandler.setComparator(dateColumn, new Comparator<Activity>() {
@Override
public int compare(Activity a1, Activity a2) {
if (a1 == a2) {
return 0;
}
// compare the date columns
if (a1 != null) {
if (a2 != null) {
long a1Val = a1.getDate().getTime();
long a2Val = a2.getDate().getTime();
if (a1Val == a2Val) {
return 0;
}
else if (a1Val > a2Val) {
return 1;
}
else {
return -1;
}
}
else {
return 1;
}
}
return -1;
}
});
// add sort handler to table
table.addColumnSortHandler(sortHandler);
// add date column to table's sort list
table.getColumnSortList().push(dateColumn);
table.setWidth("100%");
getView().getActivityPanel().add(table);
このコードでは、データがテーブルに表示され、列に並べ替え矢印が表示されます。ただし、並べ替え可能な列のヘッダーをクリックしても何も起こりません。並べ替え順序は変更されず、行は再配置されません。
誰でもここで問題を見つけることができますか? このコードは、 Google 独自の例 にあるものとほぼ同じです。