From 59157179b6e5099952f827485e16b67a88831ebf Mon Sep 17 00:00:00 2001 From: caalador Date: Thu, 2 Feb 2017 14:01:19 +0200 Subject: Add scrollTo methods to Grid (#8203) (#8410) * Add scroll methods to serverside grid (#8203) Added scrollToTop(), scrollToEnd() and scrollTo(int row) * Fix scrolling to view of opened details (#8203) Removed dependency for DetailsManagerConnector from GridConnector. GridConnector now handles one off listeners. * Rename detailsRefresh to better show that it's one-off. Add missing copyright header. --- server/src/main/java/com/vaadin/ui/Grid.java | 55 ++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'server/src') diff --git a/server/src/main/java/com/vaadin/ui/Grid.java b/server/src/main/java/com/vaadin/ui/Grid.java index bab686ed7f..8e12b4a20b 100644 --- a/server/src/main/java/com/vaadin/ui/Grid.java +++ b/server/src/main/java/com/vaadin/ui/Grid.java @@ -78,12 +78,14 @@ import com.vaadin.shared.ui.grid.AbstractGridExtensionState; import com.vaadin.shared.ui.grid.ColumnResizeMode; import com.vaadin.shared.ui.grid.ColumnState; import com.vaadin.shared.ui.grid.DetailsManagerState; +import com.vaadin.shared.ui.grid.GridClientRpc; import com.vaadin.shared.ui.grid.GridConstants; import com.vaadin.shared.ui.grid.GridConstants.Section; import com.vaadin.shared.ui.grid.GridServerRpc; import com.vaadin.shared.ui.grid.GridState; import com.vaadin.shared.ui.grid.GridStaticCellType; import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.shared.ui.grid.ScrollDestination; import com.vaadin.shared.ui.grid.SectionState; import com.vaadin.ui.components.grid.ColumnReorderListener; import com.vaadin.ui.components.grid.ColumnResizeListener; @@ -3179,6 +3181,59 @@ public class Grid extends AbstractListing implements HasComponents, return Collections.unmodifiableList(sortOrder); } + /** + * Scrolls to a certain item, using {@link ScrollDestination#ANY}. + *

+ * If the item has visible details, its size will also be taken into + * account. + * + * @param row + * id of item to scroll to. + * @throws IllegalArgumentException + * if the provided id is not recognized by the data source. + */ + public void scrollTo(int row) throws IllegalArgumentException { + scrollTo(row, ScrollDestination.ANY); + } + + /** + * Scrolls to a certain item, using user-specified scroll destination. + *

+ * If the row has visible details, its size will also be taken into account. + * + * @param row + * id of item to scroll to. + * @param destination + * value specifying desired position of scrolled-to row, not + * {@code null} + * @throws IllegalArgumentException + * if the provided row is outside the item range + */ + public void scrollTo(int row, ScrollDestination destination) { + Objects.requireNonNull(destination, + "ScrollDestination can not be null"); + + if (row > getDataProvider().size(new Query())) { + throw new IllegalArgumentException("Row outside dataProvider size"); + } + + getRpcProxy(GridClientRpc.class).scrollToRow(row, destination); + } + + /** + * Scrolls to the beginning of the first data row. + */ + public void scrollToStart() { + getRpcProxy(GridClientRpc.class).scrollToStart(); + } + + /** + * Scrolls to the end of the last data row. + */ + public void scrollToEnd() { + getRpcProxy(GridClientRpc.class).scrollToEnd(); + } + @Override protected GridState getState() { return getState(true); -- cgit v1.2.3