Skip to content

Commit

Permalink
fix #868 Scroll loading does not work when browser zoom is not 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Oct 29, 2023
1 parent 2ddb3fd commit 0a7d4bd
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@
*
* @param <T> the type of the data table records
*/
public class BodyScrollPlugin<T> implements DataTablePlugin<T> {
public class BodyScrollPlugin<T>
implements DataTablePlugin<T>, HasPluginConfig<T, BodyScrollPlugin<T>, BodyScrollPluginConfig> {

private BodyScrollPluginConfig config = new BodyScrollPluginConfig(0);

/** {@inheritDoc} */
@Override
Expand All @@ -44,12 +47,30 @@ public void onBodyAdded(DataTable<T> 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<T> 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 */
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 0a7d4bd

Please sign in to comment.