我正在尝试使用GWT显示数据:数据网格,但它并没有显示出来。
public class DataGridDemo extends Composite {
interface MyUiBinder extends UiBinder<Widget, DataGridDemo> {}
private static MyUiBinder uiBinder = GWT.create(MyUiBinder.class);
protected static UserServiceAsync userService = GWT.create(UserService.class);
@UiField
DataGrid<UserDTO> dataGrid;
private List<UserDTO> userList;
@UiField
Pagination dataGridPagination;
private SimplePager dataGridPager = new SimplePager();
private ListDataProvider<UserDTO> dataGridProvider = new ListDataProvider<UserDTO>();
public DataGridDemo(){
initWidget(uiBinder.createAndBindUi(this));
loadUsers();
}
private void loadUsers() {
AsyncCallback<List<UserDTO>> callback ;
callback = new AsyncCallback<List<UserDTO>>() {
public void onFailure(Throwable caught) {}
public void onSuccess(List<UserDTO> users) {
if(users!=null && users.size()>0){
userList=users;
initTable(dataGrid,dataGridPager, dataGridPagination, dataGridProvider);
initMockData(dataGridPagination, dataGridPager, dataGridProvider);
}
}
};
userService.getAllUsers(callback);
}
private void initMockData(final Pagination pagination, final SimplePager simplePager, final ListDataProvider<UserDTO> dataProvider) {
for (UserDTO ud : userList) {
System.out.println(ud.getFullName());
dataProvider.getList().add(ud);
}
dataProvider.flush();
pagination.rebuild(simplePager);
}
private void initTable(final AbstractCellTable<UserDTO> grid, final SimplePager pager, final Pagination pagination, final ListDataProvider<UserDTO> dataProvider) {
final TextColumn<UserDTO> col1 = new TextColumn<UserDTO>() {
public String getValue(final UserDTO object) {
return String.valueOf(object.getUsername());
}
};
grid.addColumn(col1, "Username");
final TextColumn<UserDTO> col2 = new TextColumn<UserDTO>() {
public String getValue(final UserDTO object) {
return String.valueOf(object.getFullName());
}
};
grid.addColumn(col2, "Full Name");
final TextColumn<UserDTO> col3 = new TextColumn<UserDTO>() {
public String getValue(final UserDTO object) {
return String.valueOf(object.getFundName());
}
};
grid.addColumn(col3, "Fund Name");
grid.addRangeChangeHandler(new RangeChangeEvent.Handler() {
public void onRangeChange(final RangeChangeEvent event) {
pagination.rebuild(pager);
}
});
pager.setDisplay(grid);
pagination.clear();
dataProvider.addDataDisplay(grid);
}
答案 0 :(得分:1)
DataGrid
实施RequiresResize
。 Javadoc here
这意味着您必须添加到实现具有显式高度的ProvidesResize
的Container。试试ScrollPanel
或here
关于此的更多信息:
GWT: DataGrid - set height 100% not rendering properly
PS:我假设这样,因为我看不到您的ui.xml文件。