如何获取CellTable单元格的值

时间:2014-01-17 22:19:53

标签: gwt cell celltable

我正在开发一个GWT应用程序,该应用程序使用CellTable显示2列用于面额和数量。当数量值可编辑时,面额值不可编辑。

我设想的是,如果用户选择例如5表示面额,20表示数量,则总计TextBox应自动填充5 * 20 = 100。

我的问题是,如何检索单元格的值,以便我可以进行乘法运算。

PS:这些值都存储在数据库表中。

1 个答案:

答案 0 :(得分:2)

您始终可以将selectionModel附加到单元格表以获取当前选定的行,然后获取当前所选对象及其值。我不完全确定下一个语句,但您可能也想使用FieldUpdater。请参阅GWT文档here

示例:

选择模型:

SingleSelectionModel<Contact> selectionModel = new SingleSelectionModel<Contact>();
    table.setSelectionModel(selectionModel);
    selectionModel.addSelectionChangeHandler(new SelectionChangeEvent.Handler() {
      public void onSelectionChange(SelectionChangeEvent event) {
        Contact selected = selectionModel.getSelectedObject();
        if (selected != null) {
          Window.alert("You selected: " + selected.name);
        }
      }
    });

FieldUpdater:

// Add a field updater to be notified when the user enters a new name.
    nameColumn.setFieldUpdater(new FieldUpdater<Contact, String>() {
      @Override
      public void update(int index, Contact object, String value) {
        // Inform the user of the change.
        Window.alert("You changed the name of " + object.name + " to " + value);

        // Push the changes into the Contact. At this point, you could send an
        // asynchronous request to the server to update the database.
        object.name = value;

        // Redraw the table with the new data.
        table.redraw();
      }
    });
相关问题