diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPlugin.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPlugin.java index f1c41daed..0e6ad6d93 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPlugin.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPlugin.java @@ -21,13 +21,17 @@ import org.dominokit.domino.ui.datatable.DataTable; import org.dominokit.domino.ui.datatable.events.BodyScrollEvent; import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin; +import org.dominokit.domino.ui.datatable.plugins.HasPluginConfig; /** * A plugin for handling body scroll events in a DataTable. * * @param The type of data in the DataTable. */ -public class BodyScrollPlugin implements DataTablePlugin { +public class BodyScrollPlugin + implements DataTablePlugin, HasPluginConfig, BodyScrollPluginConfig> { + + private BodyScrollPluginConfig config = new BodyScrollPluginConfig(0); /** * Initializes the plugin and adds scroll event listeners to the DataTable's body. @@ -49,12 +53,30 @@ public void onBodyAdded(DataTable dataTable) { int clientHeight = new Double(scrollElement.clientHeight).intValue(); if (JsMath.abs(offsetHeight) + JsMath.abs(scrollTop) - == new Double(scrollHeight + (offsetHeight - clientHeight)).intValue()) { + >= new Double(scrollHeight + (offsetHeight - clientHeight)).intValue() + - config.getOffset()) { dataTable.fireTableEvent(new BodyScrollEvent(ScrollPosition.BOTTOM)); } }); } + /** + * Sets up the plugin configuration. + * + * @param config The plugin configuration. + */ + @Override + public BodyScrollPlugin setConfig(BodyScrollPluginConfig config) { + this.config = config; + return this; + } + + /** @return the plugin configuration */ + @Override + public BodyScrollPluginConfig getConfig() { + return this.config; + } + /** An enum representing the scroll position in the DataTable's body. */ public enum ScrollPosition { /** Represents the top scroll position. */ diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPluginConfig.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPluginConfig.java new file mode 100644 index 000000000..4947b9f51 --- /dev/null +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPluginConfig.java @@ -0,0 +1,51 @@ +/* + * Copyright © 2019 Dominokit + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.dominokit.domino.ui.datatable.plugins.pagination; + +import org.dominokit.domino.ui.datatable.plugins.PluginConfig; + +/** + * Configuration class for {@link BodyScrollPlugin} Allow the user to define the offset of pixels + * the plugin will use to fire the event before it reach the bottom of the scroll. + */ +public class BodyScrollPluginConfig implements PluginConfig { + + private int offset; + + /** + * creates a new instance with the specified scroll offset. + * + * @param offset number of pixels to be used as scroll offset. + */ + public BodyScrollPluginConfig(int offset) { + this.offset = offset; + } + + /** @return int number of pixels to use as an offset for reaching the scroll bottom. */ + public int getOffset() { + return offset; + } + + /** + * sets the number of pixels to use as an offset for reaching the scroll bottom. + * + * @return same configuration instance + */ + public BodyScrollPluginConfig setOffset(int offset) { + this.offset = offset; + return this; + } +}