3

Is it possible to focus and open the grid cell editor directly after inserting a new row? I have searched a while but I didn't find anything helpful.

I am inserting rows with

grid.setItems(theListWithItems);

After the insertion the editor is closed and I have to double click the row to edit it. I want the editor opens immediately after inserting the new row.

Any help is highly apreciated.

Thanks in advance

F4k3d
  • 653
  • 1
  • 10
  • 29
  • 1
    see https://stackoverflow.com/questions/44324294/is-there-a-way-to-set-a-cell-in-grid-in-edit-mode-with-vaadin-8-grid – petey Jun 05 '17 at 18:59
  • So it is not possible. Thanks a lot petey. I have searched hours for a solution. Now I know it isn't possible yet in vaadin 8. – F4k3d Jun 06 '17 at 15:51

1 Answers1

1

Since Vaadin 8.2 you can now call editRow() on the grid editor

grid.getEditor().editRow(theListWithItems.size() -1);

to open the editor for the newly inserted item. But there is no focus on it, you still have to click (once, no doubleclick) into the column that you wish to edit.

However, the row is not focused only by calling editRow(). To focus a certain column I have not found a simple function for it, but I have found a way to do it nevertheless:

Each column needs a defined Editor-Component (i.e. a TextField). For the column that you want to be initially focused, define a memberfield so it can be accessed when you add a new item. Then - after you call editRow() - you can call focus() on that Editor-Component.

private TextField fooEditorTextField = new TextField();

private createGrid(){
    // create your grid as usual

    // define Editor components for grid
    grid.getEditor().setEnabled(true);
    grid.getColumn("Foo").setEditorComponent(fooEditorTextField );
    grid.getColumn("Bar").setEditorComponent(new TextField());
}

private void addNewItemToGrid(){
    MyItem newItem = new MyItem();
    theListWithItems.add(newItem);
    grid.setItems(theListWithItems);

    // open editor for new Item
    grid.getEditor().editRow(theListWithItems.size() -1);

    // Focus the "Foo" column in the editor of the new item
    fooEditorTextField.focus();
}
kscherrer
  • 5,486
  • 2
  • 19
  • 59