我正在尝试对我的CellTable进行排序,并且我遵循以下示例中提到的建议以及此处的SO答案。
http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTable CellTable: dynamically reordering rows
但解决方案都没有奏效。这是我的代码请选择我如何在表格上启用排序。
private void setComparator(ColumnSortEvent.ListHandler<MyModel> myHandler) {
table.getColumn(0).setSortable(true);
myHandler.setComparator(table.getColumn(0), new Comparator<MyModel>() {
@Override public int compare(MyModel o1, MyModel o2) {
return o1.getOrderId().compareTo(o2.getOrderId());
}
});
table.getColumn(1).setSortable(true);
myHandler.setComparator(table.getColumn(1), new Comparator<MyModel>() {
@Override public int compare(MyModel o1, MyModel o2) {
return o1.getOrderDate().compareTo(o2.getOrderDate());
}
});
table.getColumn(2).setSortable(true);
myHandler.setComparator(table.getColumn(2), new Comparator<MyModel>() {
@Override public int compare(MyModel o1, MyModel o2) {
return o1.getLastUpdated().compareTo(o2.getLastUpdated());
}
});
table.getColumn(3).setSortable(true);
myHandler.setComparator(table.getColumn(3), new Comparator<MyModel>() {
@Override public int compare(MyModel o1, MyModel o2) {
return o1.getQuantity().compareTo(o2.getQuantity());
}
});
table.getColumn(4).setSortable(true);
myHandler.setComparator(table.getColumn(4), new Comparator<MyModel>() {
@Override public int compare(MyModel o1, MyModel o2) {
return o1.getStatus().compareTo(o2.getStatus());
}
});
}
public void setTableData(MyDate tableData) {
dataProvider.setData(tableData);
}
public void addTableToPage() {
if (initialize == false) {
dataProvider.addDataDisplay(table);
initialize = true;
}
addTableElements();
}
private void addTableElements() {
addSortHandler();
theView.addTable(table);
theView.setPagerVisible(true);
}
public void addSortHandler() {
ColumnSortEvent.ListHandler<SearchNewNumberOrderModel> myHandler =
new ColumnSortEvent.ListHandler<SearchNewNumberOrderModel>(
dataProvider.getOrders());
setComparator(myHandler);
table.addColumnSortHandler(myHandler);
}
设置数据的代码:
public void setData(MyModelFilter dataForTable) {
List<MyModel1> modelList = dataForTable.getList();
setOrderList(modelList);
updateRowCount();
}
private void setOrderList(List<MyModel11> list) {
if (!UtilityService.isEmpty(list)) {
for (myModel1 element : list) {
MyModel model = new MyModel();
model.setfield1(element.getfieldA());
model.setfield2(element.getfieldB());
.... and so on
orders.add(model);
}
}
}