0

我正在使用 gwt2.3

我的 celltable 包含 10 行 5 列。

第一行的所有单元格都是空的,可编辑。

每当用户单击列单元格时,让我们说第一行 X 第三列,然后用户将编辑该单元格说“xyz”。之后,当用户单击按钮时:“更新列单元格”,然后将 xyz 值设置为该列中存在的所有单元格。

我在单元格表中使用不同的单元格类型。

如何设置/更新编辑第一个单元格的特定列/页面中的所有单元格值

对此问题的任何帮助或指导将不胜感激

4

1 回答 1

5

创建一个 FieldUpdater 以将更改推送回您的 Domain 对象。然后在按钮的 onClick 回调中使用第一行的值更新您的列表。

例如,对于将 MyDTO 类(可以是任何域对象)作为值类型的任意 TextInputColumn,您可以定义以下 FieldUpdater:

myColumn.setFieldUpdater(new FieldUpdater() {

    @Override
    public void update(int index, MyDTO object, String value) {
        // Push the changes into the MyDTO. At this point, you could send an
        // asynchronous request to the server to update the database.
        object.someField = value;

        // Redraw the table with the new data.
        table.redraw();
    }
});

您必须为所有 5 列设置这样的 FieldUpdater。(someField 是您要更新的 DTO 中的字段)。

现在在按钮的 onClick() 回调中,您必须更新实际列表。看起来像这样:

update_column_cell.addClickHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
         //Supose listDataProvider is the instance of your DataSource for your CellTable
         List<MyDTO> list = listDataProvider.getList();
         // get cell values for the first row (this is for one cell)
         newSomeField = list.get(0).someField;
         newSomeField2 = list.get(0).someField2;
         for (int i = 1;i<list.size();i++) {
              MyDTO dto = list.get(i);
              if (newSomeField != null && newSomeField.isNotEmpty()) {
                    dto.someField = newSomeField;
              }
              if (newSomeField2 != null && newSomeField2.isNotEmpty()) {
                    dto.someField2  = newSomeField2;
              }
         }
    }
})

此示例仅处理 DTO 的两个字段。您可能需要扩展它以覆盖您在 CellTable 中显示为列的所有 5 个字段

于 2011-09-05T14:51:27.260 回答