Formatter of label field lost after repaint of table

It looks like the formatter assigned to a label is lost, if the table is repainted (e.g. a row is added).
The label has a valueSource (ContainerValueSource) and a formatter to format the BigDecimal value as a formatted currency string (e.g. 8 becomes “8.00 €”)

As soon as an item is added to the underlying CollectionPropertyContainer the format is lost and only the number (e.g. 8) is displayed.

1 Like


could you clarify how do you set a formatter? Do you use the Label in the generated column?

Yes, exactly. It is a generated column creating a label with a formatter and also a value source:

        table.addGeneratedColumn(columnId) { invoiceEntry ->
            val label: Label<BigDecimal> = uiComponents.create(Label.NAME)
            val valueSource: ContainerValueSource<InvoiceEntry, BigDecimal> =
                ContainerValueSource(table.getInstanceContainer(invoiceEntry), columnId)
            label.valueSource = valueSource
            label.setFormatter { formatInvoiceEntry(invoiceEntry) }

Try to change order of setting valueSource and formatter:

label.setFormatter { formatInvoiceEntry(invoiceEntry) }
label.valueSource = valueSource

Probably, formatter isn’t invoked because value was set before.

1 Like

@pinyazhin Thanks, awesome, that works. :slight_smile: