Smooth table navigation and uneditable column cell updates from property change event

As we know in order to get smooth cursor navigation across editable cells in a table we have to use the following codes (workaround until the issue is fixed). This is working fine.

@Subscribe
public void onInit(InitEvent event) {
    //for smooth keyboard Navigation (workaround to table bug)
    salaryReviewsTable.getColumns().forEach(column -> {
        if (!column.isEditable()) {
                column.setColumnGenerator(project -> {
                    MetaPropertyPath mpp = column.getMetaPropertyPathNN();
                    Object value = project.getValueEx(mpp);
                    return new Table.PlainTextCell(metadataTools.format(value));
                });
        }
    });
}

However, the side effect is, a column “increase percentage” is not showing up any update anymore when I update the “increase amount” column.

The following code to calculate “increasePercent” only when I remove the code above. How can I get both working?

if("increaseAmount".equals(event.getProperty())){
            if(event.getValue()!=null){
                event.getItem().setIncreasePercent((double)event.getValue()/event.getItem().getEmployee().getGrossSalary()*100);
            }
        }

Hello!

For the increase percentage column you should create Label component and bind it with data container:

if ("increaseAmount".equals(column.getIdString())) {
    Label<String> label = uiComponents.create(Label.NAME);
    label.setValueSource(
            new ContainerValueSource<>(
                    ordersTable.getInstanceContainer(project), "increaseAmount"));
    return label;
}

Thank you Roman. It worked. I have coded as follows. Do I have to maintain both for “IncreasePercent” and “else” or only the code within the “increassePercent” will do for all the uneditable columns?

//for smooth keyboard Navigation (workaround to table bug)
        salaryReviewsTable.getColumns().forEach(column -> {
            if (!column.isEditable()) {
                column.setColumnGenerator(project -> {

                    if ("increasePercent".equals(column.getIdString())) {
                        Label<String> label = uiComponents.create(Label.NAME);
                        label.setValueSource(
                                new ContainerValueSource<>(
                                        salaryReviewsTable.getInstanceContainer(project), "increasePercent"));
                        return label;
                    }else {
                        MetaPropertyPath mpp = column.getMetaPropertyPathNN();
                        Object value = project.getValueEx(mpp);
                        return new Table.PlainTextCell(metadataTools.format(value));
                    }
                });
            }

        });

Label component is needed only for the increasePercent column because it depends on runtime changes in the entity and should be notified.
Table.PlainTextCell does not provide data binding as it is the lightweight component for the table.

1 Like