From ec0b52a1b6c506a184121c303adb5e4e4711b8f3 Mon Sep 17 00:00:00 2001 From: Henri Sara Date: Wed, 22 Mar 2017 08:37:57 +0200 Subject: Optimize grid by avoiding redundant row refreshes (#8874) * Optimize grid by avoiding redundant row refreshes * Delay more calls to refreshBody() --- .../main/java/com/vaadin/client/widgets/Grid.java | 27 +++++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/client/src/main/java/com/vaadin/client/widgets/Grid.java b/client/src/main/java/com/vaadin/client/widgets/Grid.java index 0b0642668f..50616c7930 100755 --- a/client/src/main/java/com/vaadin/client/widgets/Grid.java +++ b/client/src/main/java/com/vaadin/client/widgets/Grid.java @@ -4181,6 +4181,8 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, private RendererCellReference rendererCellReference = new RendererCellReference( (RowReference) rowReference); + private boolean refreshBodyRequested = false; + private DragAndDropHandler.DragAndDropCallback headerCellDndCallback = new DragAndDropCallback() { private final AutoScrollerCallback autoScrollerCallback = new AutoScrollerCallback() { @@ -4907,7 +4909,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, } if (grid != null) { - grid.refreshBody(); + grid.requestRefreshBody(); } } return this; @@ -6200,7 +6202,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, if (isAttached()) { refreshHeader(); - refreshBody(); + requestRefreshBody(); refreshFooter(); } } @@ -6313,6 +6315,19 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, escalator.getBody().refreshRows(0, escalator.getBody().getRowCount()); } + /** + * Request delayed refresh of all body rows. + */ + private void requestRefreshBody() { + if (!refreshBodyRequested) { + refreshBodyRequested = true; + Scheduler.get().scheduleFinally(() -> { + refreshBodyRequested = false; + refreshBody(); + }); + } + } + /** * Refreshes all footer rows */ @@ -7812,7 +7827,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, selectionColumn.initDone(); } else { selectionColumn = null; - refreshBody(); + requestRefreshBody(); } updateFrozenColumns(); @@ -7842,7 +7857,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, } // Refresh rendered rows to update selection, if it has changed - refreshBody(); + requestRefreshBody(); } /** @@ -8510,7 +8525,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, public void setCellStyleGenerator( CellStyleGenerator cellStyleGenerator) { this.cellStyleGenerator = cellStyleGenerator; - refreshBody(); + requestRefreshBody(); } /** @@ -8532,7 +8547,7 @@ public class Grid extends ResizeComposite implements HasSelectionHandlers, */ public void setRowStyleGenerator(RowStyleGenerator rowStyleGenerator) { this.rowStyleGenerator = rowStyleGenerator; - refreshBody(); + requestRefreshBody(); } /** -- cgit v1.2.3