GridPro allow setEnterNextRow to add rows


I’ve setup a very simple GridPro to allow editing of User objects, i.e.

GridPro<User> grid = new GridPro<>(PAGE_SIZE);
// .. Name
		.text((ItemUpdater<User, String>) User::setName)
// .. Email
		.text((ItemUpdater<User, String>) UsersMappingService.UserMapping::setEmail)

and then enabled the enterNextRow behaviour with:


This allows the user to quickly move from one row/cell to the next which is very nice. However there’s no obivious way to trigger in the case of the last row in order to add a new row (kinda-like spreadsheet behaviour) would would be much nicer than the usual method of having a discrete “+”/“Add” button.

I’ve looked at the Java source and there’s no easy way to get this bevhaviour (there’s no @DomEvent listener for the enter-next-row, checking the grid.getEditor().isOpen() returns false always in a “keyup” event listener, there’s no CellEditFinishedEvent to match CellEditStartedEvent to track the state myself etc.)

Related to this I have an additional issue in that if I use the following to add a new empty row the editor is not started properly … i.e. the focus is not moved to the 1st field in the new row:

User newRow = new User();

Any ideas?

I had one other issue which I managed to solve myself with the following workaround in-case it helps someone else.

If a new row is added with the code above, then I also wanted to scroll to the end of the grid to ensure this row was visible. However following a grid.getDataProvider().getItems().add(newRow) the grid.scrollToEnd() method does not work.
Instead I found that I had to wait a little before requesting the scrolling … so the logic for my add button is as follows:

Button addUserButton = new Button(new Icon(VaadinIcon.PLUS_CIRCLE));
addUserButton.addClickListener(ev -> {
	User newUser = new User();
	grid.getEditor().editItem(newUser); // This doesn't really start editing the row

    // Perform the Scroll to 50ms in the future (allow UI update first)
    addUserButton.getUI().ifPresent(ui -> 
	    newSingleThreadScheduledExecutor().schedule(() -> 
		    ui.access(() -> grid.scrollToEnd()), 50, TimeUnit.MILLISECONDS));