From da2e630ec354c4b4a84c284b396a20029ae152b7 Mon Sep 17 00:00:00 2001 From: Javier Godoy <11554739+javier-godoy@users.noreply.github.com> Date: Wed, 29 Dec 2021 14:10:34 -0300 Subject: [PATCH] fix: disable reordering when the grid is sorted --- .../vaadin/addons/twincolgrid/TwinColGrid.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java index 7d79b4a..1fa285f 100644 --- a/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java +++ b/src/main/java/com/flowingcode/vaadin/addons/twincolgrid/TwinColGrid.java @@ -102,6 +102,10 @@ ListDataProvider getDataProvider() { Collection getItems() { return getDataProvider().getItems(); } + + boolean isReorderingEnabled() { + return allowReordering && grid.getSortOrder().isEmpty(); + } } /** enumeration of all available orientation for TwinGolGrid component */ @@ -750,8 +754,10 @@ private void configDragAndDrop( draggedItems.addAll(event.getDraggedItems()); } - sourceModel.grid.setDropMode(sourceModel.allowReordering ? GridDropMode.BETWEEN : null); - targetModel.grid.setDropMode(targetModel.allowReordering ? GridDropMode.BETWEEN : GridDropMode.ON_GRID); + sourceModel.grid + .setDropMode(sourceModel.isReorderingEnabled() ? GridDropMode.BETWEEN : null); + targetModel.grid.setDropMode( + targetModel.isReorderingEnabled() ? GridDropMode.BETWEEN : GridDropMode.ON_GRID); }); sourceModel.grid.addDragEndListener( @@ -787,7 +793,7 @@ private void configDragAndDrop( sourceModel.grid.addDropListener(event -> { event.getDropTargetItem().ifPresent(dropOverItem -> { - if (sourceModel.allowReordering + if (sourceModel.isReorderingEnabled() && event.getSource() == draggedGrid && !draggedItems.contains(dropOverItem) && !draggedItems.isEmpty()) {