A question concerning Vaadin 11 Grid based on this starter app, a list of imaginary products.
public SampleCrudView() {
setSizeFull();
HorizontalLayout topLayout = createTopBar();
grid = new ProductGrid();
grid.setDataProvider(dataProvider);
//comment this out -->
// grid.asSingleSelect().addValueChangeListener(event -> viewLogic.rowSelected(event.getValue()));
//<- comment this out
form = new ProductForm(viewLogic);
...
public HorizontalLayout createTopBar() {
...
//added ->
Button btn = new Button("Show selected");
btn.addClickListener(event -> btn.getUI().get()
.access(() -> Notification.show(grid.getSelectedItems().iterator().next().getProductName())));
topLayout.add(btn);
//<- added
return topLayout;
}
After these changes you will be able to select an item in the product list. If you now press the button "Show selected", the notification with the product name will appear.
Now keep the selection and enter some gibberish in the filter above the list. The list will become empty, but you still will be able to retrieve the name of the previously selected product, although it is not present in the list any more.
Any suggestions?
Regards,
m_OO_m