简体   繁体   English

使用vaadin表编辑行中的特定单元格值

[英]Edit particular cell value in row using vaadin table

I am new to Vaadin 7. Am facing a problem with vaadin table. 我是Vaadin 7的新手。vaadin表遇到问题。 Currently my data displaying in vaadin table, in that table each row got one button. 目前,我的数据显示在vaadin表中,该表中的每一行都有一个按钮。 When I click that button, I want to change particular cell value in the same row. 当我单击该按钮时,我想更改同一行中的特定单元格值。

Ex: In a row I have two columns "name" and "button". 例如:在一行中,我有两列“名称”和“按钮”。 When I click button i want change name value in same row. 当我单击按钮时,我想更改同一行中的名称值。

Here, I have tried sample code for above my issue: 在这里,我已经尝试了以上问题的示例代码:

Table table = new Table();
table.addContainerProperty("Name", String.class, null);
table.addContainerProperty("Click", Button.class, null);
for (int i=0; i<5; i++) {
Button bt_click = new Button("show");
bt_click.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Notification.show("Trying");
}
});
 table.addItem(new Object[] {"ABC"+i, bt_click },i);
}

After that when I click a button in row, I have stuck how do I have to do change the column Name value inside button click event. 之后,当我单击行中的按钮时,我陷入了如何更改按钮单击事件内的列名值的问题。

You could store the item id using the Button's data field. 您可以使用“按钮”的数据字段存储商品ID。 It would look something like this: 它看起来像这样:

        final Table table = new Table();
        table.addContainerProperty("Name", String.class, null);
        table.addContainerProperty("Click", Button.class, null);
        for (int i=0; i<5; i++) {
        final Button bt_click = new Button("show");
        bt_click.setData(i);
        bt_click.addClickListener(new Button.ClickListener() {
        public void buttonClick(ClickEvent event) {
            Item item = table.getItem(bt_click.getData());
            item.getItemProperty("Name").setValue("New Name");
            Notification.show("Trying");

        }
        });
         table.addItem(new Object[] {"ABC"+i, bt_click },i);
        }

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

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