Repaint Table column

Hi, is it possible to repaint just one cell or column of a Table? (CUBA 7.2)

I ask because I have an attribute that is calculated from two other attributes from the entity. The table has editable columns and when I exit a TextField component (editable cell in the table) I catch the change via a ValueChangeListener and update the aforementioned attribute, but when I do so, it won’t be displayed in the table.
Now I can do a table.repaint() - this will display my newly calculated value, but will lose the focus on the table. But the focus is still required, because I want the user to be able to fill in the next column painlessly (without clicking in the required field again).

Hello,

unfortunately, the table cannot repaint only one cell or column. We have known issue with editable columns and focus in the table: Editable Table - Wrong focus FW 7+. I can suggest setting column generator to all non-editable columns:

@Subscribe
public void onInit(InitEvent event) {
    for (Table.Column<Customer> column : customersTable.getColumns()) {
        if (!column.isEditable()) {
            column.setColumnGenerator(customer -> {
                Object value = customer.getValueEx(column.getIdString());
                return new Table.PlainTextCell(metadataTools.format(value));
            });
        }
    }
}

And also set the generator to the column which should have calculated value and bind it with value source:

@Install(to = "customersTable.name", subject = "columnGenerator")
private Component customersTableNameColumnGenerator(Customer customer) {
    Label<String> label = uiComponents.create(Label.NAME);
    label.setValueSource(new ContainerValueSource<>(
            customersTable.getInstanceContainer(customer), "name"));
    return label;
}

So in this case, you do not have to invoke table.repaint() as label value will be changed after an entity’s property changed. See attached demo project: demo.zip (86.6 KB)

1 Like

@Pinyazhin Nice, thanks, that worked. :slight_smile: