0

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?

Screenshot

Regards,

m_OO_m

m_OO_m
  • 55
  • 7
  • Unselect everything before applyting the filter, if you dont like this behaviour? – cfrick Dec 06 '18 at 09:49
  • Yes sure, that could be a workaround: deselect prior to filtering and then select again if the row is still there (provided a suitable event listener for "after fetch"). But frankly speaking: is it a bug or a feature? – m_OO_m Dec 06 '18 at 11:05
  • IMHO a feature. – cfrick Dec 06 '18 at 11:07
  • And what is the use case? – m_OO_m Dec 06 '18 at 11:09
  • filter, select, filter, select, ... – cfrick Dec 06 '18 at 11:10
  • .. I mean, what is it good for? Keeping the selected value, where it is not present any more. I don't use in memory filtering in my prog, the corresponding object should not be there at all, it has not been fetched! – m_OO_m Dec 06 '18 at 11:30

0 Answers0