when i drag multiple items (more than the ones currently visible on screen for example 20 items selected but only 10 are visible due to its size) in the event only the visible are sent. Is it a bug or am i doing something wrong ?
It’s not a bug, but a limitation: when you drag a selected row, the drag start event only has the selected rows that are visible in the grid. Rows that are scrolled out of view are left out by default.
The server knows the whole selection, so you can take the items from there:
// Show the number of all selected rows in the drag image
grid1.addSelectionListener(e -> grid1.setSelectionDragDetails(
e.getAllSelectedItems().size(), null));
grid1.addDragStartListener(event -> {
var visibleItems = event.getDraggedItems();
var selectedItems = grid1.getSelectedItems();
// A selected row is dragged: use the whole selection
draggedItems = selectedItems.containsAll(visibleItems)
? List.copyOf(selectedItems)
: visibleItems;
grid1.setDropMode(GridDropMode.ON_GRID);
grid2.setDropMode(GridDropMode.ON_GRID);
});
If the drop moves the rows to the other grid, also deselect them, for example with grid1.asMultiSelect().deselect(draggedItems). Removed items stay selected otherwise.
That was the solution that i used but the drag indicator shows the number of dragged items and that may confuse the user … maybe it’s better to remove the number of items dragged
The selection listener in my snippet should fix it: setSelectionDragDetails(count, null) makes the drag image show the count you give it, so with 20 selected rows it shows 20. Did you add that part too?