I’ve implemented drag and drop for a TreeGrid in our project but I’m finding it a bit sketchy. If I implement the following code as per your documentation it works reliably but with a big drawback as described after this code segment.
treeGrid.addDragStartListener(e -> {
treeGrid.setDropMode(GridDropMode.ON_TOP_OR_BETWEEN);
dragItem = e.getDraggedItems().get(0);
});
treeGrid.addDragEndListener(e -> {
treeGrid.setDropMode(null);
dragItem = null;
});
Every time a drag-drop operation is performed a complete data reset is performed - found by looking at what happens when TreeGrid.setDropMode() is called in your code. The problem with the reset is that the contents of the TreeGrid are scrolled back to the top which is a terrible experience for the user when operating on a larger set of data with an active scrollbar.
public void setDropMode(GridDropMode dropMode) {
this.getElement().setProperty("dropMode", dropMode == null ? null : dropMode.getClientName());
this.getDataCommunicator().reset();
}
If I omit calling setDropMode() from the TreeGrid.addDragStartListener() and instead call it once at the point of creating the TreeGrid, then the drag-drop works once but then starts failing so it looks as though it needs calling each time a drag is started.
I’ve tried using the TreeGrid.scrollToIndex() function but couldn’t get it to work (the example in your cookbook doesn’t seem to work for a TreeGrid). Also it wouldn’t really fix the issue because the reset and hence the scroll to top occurs once at the drag start and again at the drag end (TreeGrid.setDropMode() called on both these occasions).
Is this something that can be fixed by your development team?