Grohas
Grohas

Reputation: 23

How I can transfer 1 item from table to another table in vaadin

I create a table to pass rows (checkbox == true) from another table. But table1 does not get the value. What am I doing wrong?

protected void doExportExcel() {

    Table table1 = new Table ();
    for (Iterator<?> iterator = table.getItemIds().iterator(); iterator.hasNext(); ) {
        String trueID = (String) iterator.next();
        Item item = table.getItem(trueID);
        CheckBox cb = (CheckBox) item.getItemProperty("Select").getValue();
        if (cb.getValue()) {
            table1.addItem(item);
        }
    }
    excelExport = new ExcelExportCustom(table1, "Лист 1");
    excelExport.excludeCollapsedColumns();
    excelExport.export();


}

Upvotes: 0

Views: 98

Answers (1)

J. Diogo Oliveira
J. Diogo Oliveira

Reputation: 141

The problem I see is that you're adding the same item (instance) in 2 different places. You could clone that component and take care of the sync between the two (if needed) or you could create a new component and then use Binder to make sure the value is in sync.

The example below refers binding data to forms but you can use it for binding almost anything.

https://vaadin.com/docs/v14/flow/binding-data/tutorial-flow-components-binder

Upvotes: 1

Related Questions