GWT DataGrid:无法显示数据
GWT DataGrid: Unable to display data
我正在尝试使用 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);
}
DataGrid
实现 RequiresResize
。 Javadoc here
这意味着您必须添加到实现 ProvidesResize
且具有显式高度的 Container。尝试 ScrollPanel
或 here
中列出的任何一个
有关此内容的更多信息:
GWT DataGrid automatic height
GWT: DataGrid - set height 100% not rendering properly
PS:我假设这是因为我看不到你的 ui.xml 文件。
我正在尝试使用 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);
}
DataGrid
实现 RequiresResize
。 Javadoc here
这意味着您必须添加到实现 ProvidesResize
且具有显式高度的 Container。尝试 ScrollPanel
或 here
有关此内容的更多信息:
GWT DataGrid automatic height
GWT: DataGrid - set height 100% not rendering properly
PS:我假设这是因为我看不到你的 ui.xml 文件。