我正在使用gwt2.3
我的手机包含10行,5列。
第1行中的所有单元格都是空的,可编辑。
每当用户点击列单元格时,请说出第1行X第3列 然后用户将编辑该单元格说“xyz”。 之后,当用户点击按钮时:“更新列单元格”,然后将xyz值设置为该列中的所有单元格。
我在细胞表中使用不同的细胞类型。
如何设置/更新编辑第一个单元格的特定列/页面中的所有单元格值
任何有关此事的帮助或指导都将不胜感激
答案 0 :(得分:5)
创建FieldUpdater,以便将更改推回到Domain对象。然后在按钮的onClick回调中使用第一行中的值更新List。
例如,对于任意TextInputColumn,它将MyDTO类(可以是任何域对象)作为值类型,您可以在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个字段