0

I have a large set of data that needs virtual scrolling and I use PrimeNg v13.4.0 with angular/cdk v13.3.7. I have exactly the same issue with PrimeNg demo. When scrolling down, the sticky header works well, but when scrolling up, it start jumping, the faster scroll, the bigger jump. Does anyone has any solution for this? enter image description here

Hoàng Nguyễn
  • 1,121
  • 3
  • 33
  • 57

1 Answers1

2

This issue and its pull request is added to version 13 future milestone which has no due date. https://github.com/primefaces/primeng/milestone/175

For now you can do this solution:
If you slow down the wheel speed of the cdk-virtual-scroll-viewport, even slightly,
The thead works as it should without any jumping.

changeWheelSpeed(container, speedY) {
    var scrollY = 0;
    var handleScrollReset = function() {
        scrollY = container.scrollTop;
    };
    var handleMouseWheel = function(e) {
        e.preventDefault();
        scrollY += speedY * e.deltaY
        if (scrollY < 0) {
            scrollY = 0;
        } else {
            var limitY = container.scrollHeight - container.clientHeight;
            if (scrollY > limitY) {
                scrollY = limitY;
            }
        }
        container.scrollTop = scrollY;
    };

    var removed = false;
    container.addEventListener('mouseup', handleScrollReset, false);
    container.addEventListener('mousedown', handleScrollReset, false);
    container.addEventListener('mousewheel', handleMouseWheel, false);

    return function() {
        if (removed) {
            return;
        }
        container.removeEventListener('mouseup', handleScrollReset, false);
        container.removeEventListener('mousedown', handleScrollReset, false);
        container.removeEventListener('mousewheel', handleMouseWheel, false);
        removed = true;
    };
}

implement it in the ngAfterViewInit function:

ngAfterViewInit(): void {
    const el = document.querySelector<HTMLElement>('.cdk-virtual-scroll-viewport');
    this.changeWheelSpeed(el, 0.99);
}
yoelb00
  • 161
  • 7
  • Thanks, this works pretty well. By the way, virtual scrolling blocks rowGroup feature, do you have any idea how to have rowGroup working with virtual scrolling? – Hoàng Nguyễn May 19 '22 at 09:26
  • If you're here in 2023, this solution works if you use the scrollwheel or trackpad, but it won't work if you click on the scroll bar and drag it up and down, we still see the boucing/flickering. – Gabriel Câmara Mar 30 '23 at 22:08