2011-09-05 129 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个字段