簡體   English   中英

GWT CELLTABLE列的單元格值更新

[英]GWT CELLTABLE column's cell value updation

我正在使用gwt2.3

我的單元格包含10行5列。

第一行中的所有單元格均為空,可編輯。

每當用戶單擊列單元格時說第一行X第三列,然后用戶將編輯該單元格說“ xyz”。 之后,當用戶單擊按鈕:“更新列單元”時,xyz值設置為該列中存在的所有單元。

我在celltable中使用了不同的細胞類型。

如何設置/更新第一個單元格被編輯的特定列/頁面中的所有單元格值

在這方面的任何幫助或指導將不勝感激

創建一個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個字段

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM