What you’re effectively doing is creating a string in place of the button with the concatenation operator ‘+’ (item.getItemProperty(TASK_NAME).setValue(
taskDesc+“\r\n”+btn )
And you can’t use newline characters to format layout, it only works for pure text content, not for other components/widgets.
And since your column property type is set to String (container.addContainerProperty(TASK_NAME,
String.class , null);), it’s content will always be presented as a string, no other content is possible.
What you need to do is set the column property type to some layout, preferrably CssLayout (fastest), and then insert instances of that layout into the cell. Then the layout should contain your actual information, in this case ‘taskDesc’ and ‘btn’.
Here’s some code, not tested, but I hope you get the picture:
When creating your button, set the item data into the button’s data filed via button.setData. Then, in a click listener, use getData to fetch your associated data
I don’t think it’s a cleaner way. Correct me if I am wrong, but:
Original implementation allows for 1 static instance of DetailInfoListener
Which saves a TON of ram (over all the buttons created in each row * for each of the users on the server).
I would expect the memory overhead of the second solution (compared to one static listener) to be around 30 bytes per listener or possibly even less (assuming it doesn’t use a new copy of “my data”). Probably quite small compared to all the other overhead you have for the data on each row. If you are keeping in memory so many rows that this is a problem, you should consider using lazy loading instead.
In Vaadin 7 calling on BeanItemContainer, to be precise
container.addContainerProperty
throws
“Use addNestedContainerProperty(String) to add container properties”
but nested property is not what I want, I need to add button into tepi Filtered table which opens dialog when pressed. I used generated column before, but it’s not suported by Filtered table
I got somewhere with GeneratedPropertyContainer which adds desired column with CssLayout and buton into FilterTable, works fine except the table doesn’t sort, nor it does filter - throws exception instead
I am displaying the data in 3 columns & multiple rows using Vaadin Table.
I want to add the delete button in each row just next to the score.
I have given the code for my buttons and grid below.
Attachment has the current layout of the table.
private Button addNew = new MButton(VaadinIcons.PLUS, this::add);
private Button edit = new MButton(VaadinIcons.PENCIL, this::edit);
private Button delete = new ConfirmButton(VaadinIcons.TRASH,
“Are you sure you want to delete this entry?”, this::remove);
private MGrid list = new MGrid<>(User.class) .withProperties(“id”, “name”, “score”) .withColumnHeaders(“User id”, “User Name”,“Score”) .withFullWidth();