aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorMartín López <mlopez@flowingcode.com>2020-05-11 04:00:35 -0300
committerGitHub <noreply@github.com>2020-05-11 10:00:35 +0300
commit4786732d33f2d7fc1be7268a1033707776f3a925 (patch)
tree19c0725e031a7ab73979314638e8ee8f4c5e5e82 /server
parent887f569fb99599fca9be3a5816481376294cf2c5 (diff)
downloadvaadin-framework-4786732d33f2d7fc1be7268a1033707776f3a925.tar.gz
vaadin-framework-4786732d33f2d7fc1be7268a1033707776f3a925.zip
Refresh DataProvider only once when reordering the grid using GridRowDragger (#11981)
Fixes #10844
Diffstat (limited to 'server')
-rw-r--r--server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java6
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java20
2 files changed, 25 insertions, 1 deletions
diff --git a/server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java b/server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java
index 56ebe406ca..6b21981f24 100644
--- a/server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java
+++ b/server/src/main/java/com/vaadin/ui/components/grid/GridRowDragger.java
@@ -381,7 +381,11 @@ public class GridRowDragger<T> implements Serializable {
}
sourceItems.removeAll(droppedItems);
- listDataProvider.refreshAll();
+
+ // if reordering the same grid, DataProvider's refresh will be done later
+ if (getGridDragSource().getGrid() != getGridDropTarget().getGrid()) {
+ listDataProvider.refreshAll();
+ }
}
private void handleTargetGridDrop(GridDropEvent<T> event, final int index,
diff --git a/server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java b/server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java
index 08b647cdde..6c522abcf9 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/grid/GridRowDraggerOneGridTest.java
@@ -128,6 +128,26 @@ public class GridRowDraggerOneGridTest {
}
@Test
+ public void listDataProvider_calledOnlyOnce() {
+
+ final int[] times = new int[1];
+
+ source.setItems("0", "1", "2");
+
+ source.getDataProvider().addDataProviderListener(ev -> times[0]++);
+
+ dragger.setDropIndexCalculator(event -> {
+ return Integer.MAX_VALUE;
+ });
+
+ drop("1", DropLocation.ABOVE, "0");
+
+ verifyDataProvider("1", "2", "0");
+
+ Assert.assertArrayEquals("DataProvider should be invoked only once", new int[] { 1 }, times);
+ }
+
+ @Test
public void noopSourceUpdater() {
source.setItems("0", "1", "2");