我有以下代码,它创建一个单元格表并将SimplePager添加到它。
public class CellTableTestClass {
private VerticalPanel applicationPanel = new VerticalPanel();
private CellTable<Contact> cellTable = new CellTable<Contact>();
public VerticalPanel createContent() {
List<Contact> list=Arrays.asList(new Contact("John","123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact("Zander", "94 Road Street"), new Contact("Harry","303 Shakti"));
cellTable.addColumn(new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.name;
}
}, "Log Name");
cellTable.addColumn(new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.address;
}
}, "Size");
// create a pager, giving it a handle to the CellTable
SimplePager.Resources pagerResources =
GWT.create(SimplePager.Resources.class);
SimplePager pager = new SimplePager(TextLocation.CENTER,
pagerResources, true, 0, true);
pager.setDisplay(cellTable);
pager.setPageSize(2);
cellTable.setRowData(0,list);
cellTable.setRowCount(list.size());
// add the Pager to the dialog
applicationPanel.add(pager);
applicationPanel.add(new HTML("<hr />"));
applicationPanel.add(cellTable);
return applicationPanel;
}
}
当我点击寻呼机的下一个按钮时,它只显示加载屏幕。谁能指出代码中可能存在的错误?
答案 0 :(得分:1)
作为mentionned here,您应该在使用cellTable时使用数据提供者。如果您不想,可以使用cellList而不是cellTable并使用cellList.setRowData()。
答案 1 :(得分:1)
以下是CellTable,SimplePager和ListDataProvider的简单示例。
CellTable<AlarmDisplayBTO> cellTable= new CellTable<AlarmDisplayBTO>();
TextColumn<AlarmDisplayBTO> dateColumn = new TextColumn<AlarmDisplayBTO>() {
@Override
public String getValue(AlarmDisplayBTO object) {
return object.getDate();
}
};
cellTable.addColumn(dateColumn, "Date");
TextColumn<AlarmDisplayBTO> alarmNameColumn = new TextColumn<AlarmDisplayBTO>() {
@Override
public String getValue(AlarmDisplayBTO object) {
return object.getAlarmName();
}
};
cellTable.addColumn(alarmNameColumn, "Alarm Name");
cellTable.setRowCount(alarmList.size());
// alarmList is an ArrayList<AlarmDisplayBTO> rendered from RPC call
cellTable.setRowData(0, alarmList);
cellTable.setEmptyTableWidget(new Label(" No Records Found"));
ListDataProvider<AlarmDisplayBTO> dataProvider = new ListDataProvider<AlarmDisplayBTO>();
dataProvider.addDataDisplay(cellTable);
dataProvider.setList(alarmList);
SimplePager pager = new SimplePager();
pager.setDisplay(cellTable);
pager.setPageSize(20); // 20 rows will be shown at a time
VerticalPanel vPanel = new VerticalPanel();
vPanel.add(cellTable);
vPanel.add(pager);
setWidget(new ScrollPanel(vPanel));
希望这可能会有所帮助..