创建简单DataGrid时出现问题

时间:2012-11-01 11:09:43

标签: java gwt

我只是想让自己熟悉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);
  }
}

1 个答案:

答案 0 :(得分:0)

我认为,这种行为的原因是我们需要明确指定 网格的高度。

 table.setHeight("300px");
这显示了我的表。 javadoc中的任何地方都没有提到它。此外,这个例子使用了DataGrid的CellTable。 :)

请随意进行更正,这可能有助于某人。

由于