简体   繁体   English

如何清除GWT CellTable上的用户输入?

[英]How to clear the user input on a GWT CellTable?

I have a CellTable<Price> table = new CellTable<Price>(); 我有一个CellTable<Price> table = new CellTable<Price>(); .

I also have a TextInputCell column: 我也有一个TextInputCell列:

        priceColumn = new Column<Price, String>(new TextInputCell()) {
            public String getValue(Price p) {
                if (p.getPrice() == 0)
                    return "";
                return p.getPrice()+"";
            }   
        };

Also I have a refresh button . 我也有一个refresh button If the button is pressed, then it basically reload all data from server and then set the data to the table. 如果按下该按钮,则基本上可以从服务器重新加载所有数据,然后将数据设置到表中。

When the table first time load data, it is fine. 当表第一次加载数据时,就可以了。 Let's say, a cell has price of 12 . 假设一个单元格的价格为12

Then if I modify that cell to 11 (or whatever value other than 12) , then the 11 stays there forever. 然后,如果我修改单元格11(或任何超过12其他值),那么11停留永远存在。 I mean, even if I press the refresh button , the cell's data will not change back to 12 , but still stay 11 . 我的意思是,即使我按refresh button ,单元格的数据不会变回12 ,但仍停留11

How can I make the column / cell not remembering the user input? 如何使列/单元格不记住用户输入?

After you received the new data and updated your objects with the new data call table.redraw(); 在收到新数据并使用新数据调用table.redraw();更新对象之后table.redraw();

Working example 工作实例

final Price p1 = new Price(4);
final Price p2 = new Price(5);
final Price p3 = new Price(6);

final CellTable<Price> table = new CellTable<Price>();

Column<Price, String> priceColumn = new Column<Price, String>(new TextInputCell()) {
    public String getValue(Price p) {
    if (p.getPrice() == 0)
        return "";
    return p.getPrice() + "";
    }
};

ListDataProvider<Price> dataProvider = new ListDataProvider<Price>();
dataProvider.addDataDisplay(table);

List<Price> list = dataProvider.getList();
list.add(p1);
list.add(p2);
list.add(p3);

table.addColumn(priceColumn);

Button b = new Button("refresh");
b.addClickHandler(new ClickHandler() {

    @Override
    public void onClick(ClickEvent event) {
    // your refresh logic, update the items already loaded into the CellTable!
    p2.setPrice(1000);
    p3.setPrice(2000);

    table.redraw();
    }
});

RootPanel.get().add(table);
RootPanel.get().add(b);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM