Select grid row after refreshing data

I’m trying to select an item on the grid right after saving it to the database however no selection is being made, what would be the correct way of doing this?

//Write item to database

//Clear selection and refresh data;

//Select newly added database item.;```

Do you have equals and hashCode implemented in the Transaction class?

Hi Simon, yes I do:

    public int hashCode() {
        if (id != null) {
            return id.hashCode();
        return super.hashCode();

    public boolean equals(Object obj) {
        if (!(obj instanceof Transaction)) {
            return false; // null or other class
        Transaction other = (Transaction) obj;

        if (id != null) {
            return id.equals(;
        return super.equals(other);

and how do you set the items?

grid.setItems(query -> transactionService.list(
                PageRequest.of(query.getPage(), query.getPageSize(), VaadinSpringDataHelpers.toSpringDataSort(query)))

public Page<Transaction> list(Pageable pageable) {
        return repository.findAll(pageable);

But only writeBean does not insert the record to the database

Ah yeah, there is more code, which was generated from the Vaadin app generator and I replace with my data class, which happens to be “Transaction”.

save.addClickListener(e -> {
            try {
                if (this.transaction == null) {
                    this.transaction = new Transaction();


      "Transaction saved.");
            } catch (ValidationException validationException) {
      "An exception happened while trying to store the transaction details.");
    private final BeanValidationBinder<Transaction> binder;
    binder = new BeanValidationBinder<>(Transaction.class);

By default saving just refreshes the grid and I added the line to select the just added transaction afterwards.

Could it be that grid.getDataProvider().refreshAll() is running async thus the selection runs first?

You could try to select it in the setItems callback

Will give it a try, that code runs when the view is loaded whereas the refresh when the save button is pressed.

Check the grid selection mode, e.g. grid.setSelectionMode. If it is set to NONE, you will not see the selection even if you set it explicitly.