All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.dominokit.domino.ui.datatable.plugins.BodyScrollPlugin Maven / Gradle / Ivy

There is a newer version: 1.0.139
Show newest version
package org.dominokit.domino.ui.datatable.plugins;

import elemental2.core.JsMath;
import elemental2.dom.DomGlobal;
import elemental2.dom.HTMLTableSectionElement;
import org.dominokit.domino.ui.datatable.DataTable;
import org.dominokit.domino.ui.datatable.events.BodyScrollEvent;

public class BodyScrollPlugin implements DataTablePlugin {
    @Override
    public void onBodyAdded(DataTable dataTable) {
        HTMLTableSectionElement tbody = dataTable.bodyElement().element();
        tbody.addEventListener("scroll", evt -> {
            double scrollTop = new Double(tbody.scrollTop).intValue();
            if (scrollTop == 0) {
                dataTable.fireTableEvent(new BodyScrollEvent(ScrollPosition.TOP));
            }
            int offsetHeight = new Double(tbody.offsetHeight).intValue();
            int scrollHeight = new Double(tbody.scrollHeight).intValue();

            if (JsMath.abs(offsetHeight) + JsMath.abs(scrollTop) == new Double(scrollHeight).intValue()) {
                dataTable.fireTableEvent(new BodyScrollEvent(ScrollPosition.BOTTOM));
            }
        });
    }

    public enum ScrollPosition{
        TOP,
        BOTTOM
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy