Skip to content

Commit 54b0e0c

Browse files
committed
fix #868 Scroll loading does not work when browser zoom is not 100%
1 parent 818d3a9 commit 54b0e0c

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/datatable/plugins/pagination/BodyScrollPlugin.java

+24-2
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,17 @@
2121
import org.dominokit.domino.ui.datatable.DataTable;
2222
import org.dominokit.domino.ui.datatable.events.BodyScrollEvent;
2323
import org.dominokit.domino.ui.datatable.plugins.DataTablePlugin;
24+
import org.dominokit.domino.ui.datatable.plugins.HasPluginConfig;
2425

2526
/**
2627
* A plugin for handling body scroll events in a DataTable.
2728
*
2829
* @param <T> The type of data in the DataTable.
2930
*/
30-
public class BodyScrollPlugin<T> implements DataTablePlugin<T> {
31+
public class BodyScrollPlugin<T>
32+
implements DataTablePlugin<T>, HasPluginConfig<T, BodyScrollPlugin<T>, BodyScrollPluginConfig> {
33+
34+
private BodyScrollPluginConfig config = new BodyScrollPluginConfig(0);
3135

3236
/**
3337
* Initializes the plugin and adds scroll event listeners to the DataTable's body.
@@ -49,12 +53,30 @@ public void onBodyAdded(DataTable<T> dataTable) {
4953
int clientHeight = new Double(scrollElement.clientHeight).intValue();
5054

5155
if (JsMath.abs(offsetHeight) + JsMath.abs(scrollTop)
52-
== new Double(scrollHeight + (offsetHeight - clientHeight)).intValue()) {
56+
>= new Double(scrollHeight + (offsetHeight - clientHeight)).intValue()
57+
- config.getOffset()) {
5358
dataTable.fireTableEvent(new BodyScrollEvent(ScrollPosition.BOTTOM));
5459
}
5560
});
5661
}
5762

63+
/**
64+
* Sets up the plugin configuration.
65+
*
66+
* @param config The plugin configuration.
67+
*/
68+
@Override
69+
public BodyScrollPlugin<T> setConfig(BodyScrollPluginConfig config) {
70+
this.config = config;
71+
return this;
72+
}
73+
74+
/** @return the plugin configuration */
75+
@Override
76+
public BodyScrollPluginConfig getConfig() {
77+
return this.config;
78+
}
79+
5880
/** An enum representing the scroll position in the DataTable's body. */
5981
public enum ScrollPosition {
6082
/** Represents the top scroll position. */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.datatable.plugins.pagination;
17+
18+
import org.dominokit.domino.ui.datatable.plugins.PluginConfig;
19+
20+
/**
21+
* Configuration class for {@link BodyScrollPlugin} Allow the user to define the offset of pixels
22+
* the plugin will use to fire the event before it reach the bottom of the scroll.
23+
*/
24+
public class BodyScrollPluginConfig implements PluginConfig {
25+
26+
private int offset;
27+
28+
/**
29+
* creates a new instance with the specified scroll offset.
30+
*
31+
* @param offset number of pixels to be used as scroll offset.
32+
*/
33+
public BodyScrollPluginConfig(int offset) {
34+
this.offset = offset;
35+
}
36+
37+
/** @return int number of pixels to use as an offset for reaching the scroll bottom. */
38+
public int getOffset() {
39+
return offset;
40+
}
41+
42+
/**
43+
* sets the number of pixels to use as an offset for reaching the scroll bottom.
44+
*
45+
* @return same configuration instance
46+
*/
47+
public BodyScrollPluginConfig setOffset(int offset) {
48+
this.offset = offset;
49+
return this;
50+
}
51+
}

0 commit comments

Comments
 (0)