我正在使用GWT 2.4并创建了一个CellTable:
table = new CellTable<Home>();
pager = new SimplePager(SimplePager.TextLocation.LEFT);
idColumn = new TextColumn<Home>() {
@Override
public String getValue(Home home) {
return home.getHomeId();
}
};
idColumn.setSortable(true);
TextColumn<Home> addressColumn = new TextColumn<Home>() {
@Override
public String getValue(Home home) {
return home.getAddress();
}
};
postcodeColumn = new TextColumn<Home>() {
@Override
public String getValue(Home home) {
return home.getPostcode();
}
};
postcodeColumn.setSortable(true);
TextColumn<Home> productColumn = new TextColumn<Home>() {
@Override
public String getValue(Home home) {
return home.getProduct();
}
};
table.addColumn(uriColumn, "");
table.addColumn(idColumn, "HomeID");
table.addColumn(addressColumn, "Address");
table.addColumn(postcodeColumn, "Postcode");
table.addColumn(productColumn, "Product");
table.setVisibleRange(0,10);
pager.setDisplay(table);
final AsyncDataProvider<Home> dataProvider = new HomesDataProvider();
// Connect the list to the data provider.
dataProvider.addDataDisplay(table);
ColumnSortEvent.AsyncHandler columnSortHandler = new ColumnSortEvent.AsyncHandler(table);
table.addColumnSortHandler(columnSortHandler);
// default sort on the home id
table.getColumnSortList().push(idColumn);
正如您所看到的那样,还使用AsyncDataProvider来获取数据,使用SimplePager进行分页。
AsyncDataProvider如下:
private class HomesDataProvider extends AsyncDataProvider<Home> {
@Override
protected void onRangeChanged(HasData<Home> homeData) {
final int start = homeData.getVisibleRange().getStart();
int length = homeData.getVisibleRange().getLength();
final ColumnSortList sortList = table.getColumnSortList();
JSONObject searchParametersJson = null;
if (sortList != null && sortList.size() > 0) {
ColumnSortList.ColumnSortInfo sortColumn = sortList.get(0);
String sortDirection = (sortColumn.isAscending()) ? "asc" : "desc";
Column<?, ?> column = sortColumn.getColumn();
int sortColumnIndex = -1;
if (column.equals(idColumn)) {
sortColumnIndex = 2;
} else if (column.equals(postcodeColumn)) {
sortColumnIndex = 4;
}
searchParametersJson = getSearchCallParameters(start, length, sortColumnIndex, sortDirection);
}
RPC.fetchHomes(searchParameters, CookieManager.getUsername(), new CallbackAction<SearchResultList<Home>>() {
@Override
public void execute(SearchResultList<Home> results) {
if (results != null && results.getResultList().size() > 0) {
updateRowCount(results.getTotalRecords(), true);
updateRowData(start, results.getResultList());
}
}
});
}
}
表格显示正常,数据正确。问题是,当我单击对列进行排序或在寻呼机上查看另一个页面时,加载图像将一直显示,直到数据加载完毕。客户说这太生涩和分散注意力,他宁愿显示从旧的行集更改为新的行集而不先清理表,如展示http://samples.gwtproject.org/samples/Showcase/Showcase.html#!CwCellTable所示。我怎么能这样做?
我试过table.setLoadingIndicator(null);这会阻止微调器出现,但在加载新数据之前它仍会清除表格。