How to Edit Vaadin 8 Grid.

Here goes the short snippet of the code for Editing Grid in Vaadin 

Code does following.
  1. Takes Grid.
  2. populates Grid.
  3. makes Grid editable property true.
  4. sets component what one needs to add when grid is edited.
  5. identifies column at the time of adding column or getting column.

grid = new Grid<>();
    lst = new ArrayList<>();
    provider = new ListDataProvider<>(lst);
    lst.add(new Company(1, "Java"));
    grid.setDataProvider(provider);
    grid.addColumn(Company::getSerialNo).setCaption("Sr.no");
    TextField tf = new TextField();

    grid.getEditor().setEnabled(true);

    HorizontalLayout hlyt = new HorizontalLayout();
    grid.addColumn(Company::getName).setEditorComponent(tf, Company::setName).setCaption("Name").setExpandRatio(2);

    hlyt.addComponent(grid);

Hope it works cheers .

Comments

Popular posts from this blog

State space search / blocks world problem by heuristic approach /TIC TAC TOE

Navigation in Vaadin.

Drag and drop items from one Grid to another