我有一个带有5列的DataGrid
表,如下所示:
| | | qty |
id | desc | price/unit | (editable field) | total price
---+---------+------------+------------------+------------
1 | my id 1 | 10 | 1 | 10
2 | my id 2 | 20 | 2 | 40
3 | my id 3 | 30 | 3 | 90
4 | my id 4 | 40 | 4 | 160
我需要的是,如果我将第1行的qty
值从1更新为10,那么它应该将第1行的total price
更新为100.如何实现此目的?
在您的可编辑列的FieldUpdater中,您有update
方法。此方法在其第一个参数中获取rowIndex
。这是您需要重绘以刷新total price
列的行。当然,我假设totatl price
是根据当前的qty
和price
值计算的。
像这样:
qtyColumn.setFieldUpdater(new FieldUpdater<RowType, String>() {
@Override
public void update(int index, RowType object, String value) {
...
object.setQty(newValue);
grid.redrawRow(index);
}
});