Simply create a string that contains the desired value and set to the label component.
Alternatively, If you want to display just dynamic text, use special class Table.PlainTextCell instead of the Label component. It will simplify rendering and make the table faster.
I need a dynamic text (integer).
I used a Transient (Integer) property lineNum but I have the next error: ‘void’ type not allowed here
int i=0;
transactionsTable.addGeneratedColumn("id", e -> {
for (Transaction c : transactionsDs.getItems()) {
Table.PlainTextCell(Integer.toString(c.setLineNum(i++)));
}
return new Table.PlainTextCell("");
});
Simply create a string that contains the desired value and return a PlainTextCell with this string:
StringBuilder sb = new StringBuilder();
int i = 0;
for (Transaction c : transactionsDs.getItems()) {
c.setLineNum(i++);
sb.append(i).append(",");
}
return new Table.PlainTextCell(sb.toString());
It appears that you need numbering for items and as I see you have the lineNum attribute for that purpose. So, I would recommend taking a look at this post. Please note that in case of the persistent attribute you don’t need (but still can) use generated column, instead add it to the XML descriptor (i.e. add a column that refers to this attribute).
Thank you very much, Gleb!
However I don’t understand why doesn’t work with just simple addGeneratedColumn (or similar) method and needs to make a Transient or a persistent new column.
You don’t need, but without detailed description from your side I’m trying to guess your data model
and your actual requirements
Going back to your problem, you can use generated columns, e.g.:
@Subscribe
private void onInit(InitEvent event) {
final int[] i = {1};
customersTable.addGeneratedColumn("number", entity ->
new Table.PlainTextCell(String.valueOf(i[0]++)));
}
Please note that in this case, the number column can’t be sortable and every time your table is repainted (e.g. if you sort another column, remove element etc.) row numbers will be incremented. That’s why in the link above it’s recommended to use the persistent property. Of course, everything depends on your requirements.