爲了逼退創建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個字段