diff options
author | caalador <mikael.grankvist@gmail.com> | 2017-02-02 14:01:19 +0200 |
---|---|---|
committer | Pekka Hyvönen <pekka@vaadin.com> | 2017-02-02 14:01:19 +0200 |
commit | 59157179b6e5099952f827485e16b67a88831ebf (patch) | |
tree | bef348f7ffb73103e25f69368a8294e48d16ae19 /server/src | |
parent | be2c4684cd43547c2785831a8b0aeda63ccbaebe (diff) | |
download | vaadin-framework-59157179b6e5099952f827485e16b67a88831ebf.tar.gz vaadin-framework-59157179b6e5099952f827485e16b67a88831ebf.zip |
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.
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/main/java/com/vaadin/ui/Grid.java | 55 |
1 files changed, 55 insertions, 0 deletions
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<T> extends AbstractListing<T> implements HasComponents, return Collections.unmodifiableList(sortOrder); } + /** + * Scrolls to a certain item, using {@link ScrollDestination#ANY}. + * <p> + * 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. + * <p> + * 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); |