From e5c37e2d29d1bb2f04cd0440a50b5f0111f77f60 Mon Sep 17 00:00:00 2001 From: "Ahmad K. Bawaneh" Date: Sun, 29 Oct 2023 20:13:51 +0300 Subject: [PATCH] fix #868 Scroll loading does not work when browser zoom is not 100% --- .../datatable/plugins/BodyScrollPlugin.java | 25 +++++++++- .../plugins/BodyScrollPluginConfig.java | 49 +++++++++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPluginConfig.java diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPlugin.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPlugin.java index a29c60937..a7d448577 100644 --- a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPlugin.java +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPlugin.java @@ -26,7 +26,10 @@ * * @param the type of the data table records */ -public class BodyScrollPlugin implements DataTablePlugin { +public class BodyScrollPlugin + implements DataTablePlugin, HasPluginConfig, BodyScrollPluginConfig> { + + private BodyScrollPluginConfig config = new BodyScrollPluginConfig(0); /** {@inheritDoc} */ @Override @@ -44,12 +47,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 to specify the postion of the scroll */ public enum ScrollPosition { /** The scroll reached the top */ diff --git a/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPluginConfig.java b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPluginConfig.java new file mode 100644 index 000000000..db69973b0 --- /dev/null +++ b/domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/BodyScrollPluginConfig.java @@ -0,0 +1,49 @@ +/* + * 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; + +/** + * 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; + } +}