Steven
(Steven Zaluk)
February 25, 2019, 6:47pm
1
Hi,
I implemented the code in the “Open details programmatically” Java example on https://vaadin.com/components/vaadin-grid/java-examples/item-details
What I want to do though is to show/hide the details button in the cells based on values in the backing data object.
In Vaadin 8, I was able to do it by following https://vaadin.com/docs/v8/framework/components/components-grid.html#components.grid.stylegeneration.cell
I don’t see that as an option in Vaadin 12. What am I missing?
Thanks,
Steve
Kaspar4
(Kaspar Scherrer)
February 26, 2019, 9:34am
2
Hi Steven
Instead of using a NativeButtonRenderer
, you could use a ComponentRenderer, where you can simply not create/add the detail button if certain conditions of the item are not met.
grid.addColumn(new ComponentRenderer<>(item -> {
if(item.customCriteriaIsMet()){
return new NativeButton("Details", click -> grid.setDetailsVisible(item, !grid.isDetailsVisible(item)));
}
return null;
}));
Stuart
(Stuart Robinson)
February 26, 2019, 1:51pm
3
Hi Steven,
I set the setDetailsVisibleOnClick to false and use my own click listener to toggle whether the details are shown or not.
That way I can ‘see if there are any details to show’ before calling setDetailsVisible.
grid.setDetailsVisibleOnClick(false);
grid.addItemClickListener(new ComponentEventListener<ItemClickEvent<MyObject>> () {
@Override
public void onComponentEvent(ItemClickEvent<MyObject> event) {
if (event.getItem() != null) {
MyObject toShow = event.getItem();
if (toShow.hasSomethingToShow()) {
grid.setDetailsVisible(toShow, !grid.isDetailsVisible(toShow)); //Switches between show and hide.
}
}
});
Hope that helps
Stuart