Created
May 2, 2017 09:56
-
-
Save alejandro-du/3b417f3c5c83bf15571c59f0158c1672 to your computer and use it in GitHub Desktop.
Vaadin 8.1 - Grid Drag and Drop example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example; | |
import com.vaadin.shared.ui.grid.DropMode; | |
import com.vaadin.ui.Grid; | |
import com.vaadin.ui.GridDragSource; | |
import com.vaadin.ui.GridDropTarget; | |
import com.vaadin.ui.VerticalLayout; | |
import java.util.List; | |
/** | |
* @author Alejandro Duarte. | |
*/ | |
public class GridDragAndDrop extends VerticalLayout { | |
private Service service = new Service(); | |
private List<Person> people = service.findAll(); | |
private Person dragged = null; | |
public GridDragAndDrop() { | |
Grid<Person> grid = new Grid<>(Person.class); | |
grid.setWidth("360px"); | |
grid.setHeight("300px"); | |
grid.setColumns("id", "firstName"); | |
grid.getColumn("id").setWidth(100); | |
grid.setItems(people); | |
GridDragSource<Person> source = new GridDragSource<>(grid); | |
source.addGridDragStartListener(e -> { | |
dragged = e.getDraggedItems().iterator().next(); | |
}); | |
GridDropTarget<Person> target = new GridDropTarget<>(grid, DropMode.ON_TOP_OR_BETWEEN); | |
target.addGridDropListener(e -> { | |
int index = people.indexOf(e.getDropTargetRow()); | |
people.remove(dragged); | |
people.add(index, dragged); | |
grid.getDataProvider().refreshAll(); | |
}); | |
addComponent(grid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Legioth would it be hard to add a shorthand for single select mode to return just a single row?