GWT正在整理一张细胞表,可能是我没看到的东西
在过去的几个小时里,我一直在努力整理GWT手机台。 这真是一个愚蠢的问题,因为它已经在这里完成了 但我不明白我在这个例子中遗漏了什么 以下是我用来创建列的代码:GWT正在整理一张细胞表,可能是我没看到的东西,gwt,sorting,gwt-2.2-celltable,Gwt,Sorting,Gwt 2.2 Celltable,在过去的几个小时里,我一直在努力整理GWT手机台。 这真是一个愚蠢的问题,因为它已经在这里完成了 但我不明白我在这个例子中遗漏了什么 以下是我用来创建列的代码: Column<RemoteCommand, String> nbProducts = new Column<RemoteCommand, String>( new TextCell()) { @Override pu
Column<RemoteCommand, String> nbProducts = new Column<RemoteCommand, String>(
new TextCell()) {
@Override
public String getValue(RemoteCommand object) {
return object.getNumberProduct();
}
};
nbProducts.setSortable(true);
sortHandler.setComparator(nbProducts, new Comparator<RemoteCommand>() {
public int compare(RemoteCommand o1, RemoteCommand o2) {
cellTable.redraw();
return o1.getCommandSize().compareTo(o2.getCommandSize());
// System.out.println(Integer.parseInt(o1.getCommandSize() ) - Integer.parseInt(o2.getCommandSize()));
// return Integer.parseInt(o1.getCommandSize() ) - Integer.parseInt(o2.getCommandSize());
}
});
下面是表本身的声明:
// Add a selection model so we can select cells.
final SelectionModel<RemoteCommand> selectionModel = new MultiSelectionModel<RemoteCommand>(
RemoteCommand.KEY_PROVIDER);
cellTable.setSelectionModel(selectionModel,
DefaultSelectionEventManager.<RemoteCommand> createCheckboxManager());
// Attach a column sort handler to the ListDataProvider to sort the list.
ListHandler<RemoteCommand> sortHandler = new ListHandler<RemoteCommand>(values);
cellTable.addColumnSortHandler(sortHandler);
// Initialize the columns.
initTableColumns(selectionModel, sortHandler);
cellTable.setRowData(values);
需要帮助:我想您已经找到了解决方案,但请将其保留在此处: 首先,使用一些已知列表创建数据提供者。 而不是用相同的列表给sortHandler喂食; 并使用列表更新数据。 Celltable应设置为dataProvider的dataDisplay:
List myDataList = new ArrayList();
ListDataProvider dataProvider = new ListDataProvider(KEY_PROVIDER);
dataProvider.setList(myDataList);
ListHandler sortHandler = new ListHandler(dataProvider.getList);
//tie provider and table
dataProvider.addDataDisplay(cellTable);
//when you need to update dataprovider
//first do some myDataList cleanup to remove old values
myListData.addAll(values);
//update data displays
dataProvider.refresh();
考虑一下,您必须始终使用同一个列表对象。干得好,从我的角度来看,这正是如何完成的-只有一件事:刷新是不必要的,因为它是在修改列表时在更新中完成的。根据我的经验,我必须使用dataProvider.getList-Method而不是myDataList-否则就不会触发更新。Chirs,你完全正确!使用dataProvider.getList更好!事实上,修改myDataList对我来说很有用,但我需要刷新,而且,最重要的是若在创建myDataList时并没有表的数据,那个么更新myDataList会导致不正确的分页行为—例如,在某些排序完成之前,分页仍然无效。非常感谢。