2011-09-05 74 views
0

我正在使用gwt2.3GWT CELLTABLE列的單元值更新

我的手錶包含10行5列。

第一行的所有單元格都是空的,可編輯。

每當用戶點擊列單元格讓我們說第1行X第3列 然後用戶將編輯該單元格說「xyz」。 之後,當用戶點擊按鈕:「更新列單元格」然後xyz值設置爲該列中存在的所有單元格。

我在celltable中使用不同的celltype。

如何設置/更新的所有單元格的值在其第一小區被編輯

在這個問題上的任何幫助或指導,將不勝感激

回答

5

爲了逼退創建FieldUpdater特定的列/頁更改您的Domain對象。然後在您的按鈕的onClick回調中使用第一行的值更新您的List。

例如,對於其中需要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(); 
    } 
}); 

必須設置這樣的FieldUpdater所有5列。 (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個字段