我只是想让自己熟悉 GWT DataGrid,我还阅读了javadoc中给出的示例。奇怪的是在 DataGrid 示例中他们正在使用 CellTable 这只是一个错字还是故意的?
此外,我从 javadoc 复制了以下代码,在 CellTable 的情况下可以正常工作,但是一旦我用 DataGrid 替换 CellTable,它就会停止工作。
任何建议都受到高度赞赏。
public class DataGridPOC implements EntryPoint {
DataGrid<Contact> table = new DataGrid<Contact>();
/**
* A simple data type that represents a contact.
*/
private static class Contact {
private final String address;
private final Date birthday;
private final String name;
public Contact(String name, Date birthday, String address) {
this.name = name;
this.birthday = birthday;
this.address = address;
}
}
/**
* The list of data to display.
*/
private static final List<Contact> CONTACTS = Arrays.asList(
new Contact("John", new Date(80, 4, 12), "123 Fourth Avenue"),
new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln"),
new Contact("George", new Date(46, 6, 6), "1600 Pennsylvania Avenue"));
public void onModuleLoad() {
// Add a text column to show the name.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.name;
}
};
table.addColumn(nameColumn, "Name");
table.addColumn(nameColumn, "Birthday");
table.addColumn(nameColumn, "Address");
// Set the total row count. This isn't strictly necessary, but it affects
// paging calculations, so its good habit to keep the row count up to date.
table.setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
table.setRowData(0, CONTACTS);
// Add it to the root panel.
RootPanel.get().add(table);
}
}