简体   繁体   中英

Get data from grid row using vaadin

I am making a CRUD application using vaadin I have a grid with an object Person (id, name, age) I made an "edit" button next to each row, but how do I get the Person value of that row when I press the button?

 grid.addComponentColumn(e -> new Button("Edit"));

The e variable on your example is the grid item, ie the Person instance. If you expand the callback to a block to add a listener to the button rather than only creating one, then you can directly reference the item in that listener.

Code for that could thus be something along these lines (assuming there's a getName() method in Person ):

grid.addComponentColumn(person -> {
  Button button = new Button("Edit");
  button.addClickListener(event -> Notification.show("Editing " + person.getName()));
  return button;
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM