When the mouse is on the grid, the container can't scroll
Hello, I have disable grid scrolling but when the mouse pointer is in the grid, the container cannot scroll. Any ideas on how I can disable this behavior?
So I had a look at the source code and found that there is an event binding on the uiGridRenderContainer directive (line 2337 on version v3.0.0-rc.12-6fa2e47) that causes this behavior.
$elm.bind('wheel mousewheel DomMouseScroll MozMousePixelScroll', function(evt) {
// use wheelDeltaY
evt.preventDefault();
...
});
Is there a reason why the grid needs to disable the browser's native scrolling? And if so, can I disable this?
Yes it needs to catch those events so it can virtualize properly. That's the whole reason for the grid, basically. On Nov 3, 2014 5:15 AM, "Caleb Kiage" [email protected] wrote:
So I had a look at the source code and found that there is an event binding on the uiGridRenderContainer directive (line 2337 on version v3.0.0-rc.12-6fa2e47) that causes this behavior.
$elm.bind('wheel mousewheel DomMouseScroll MozMousePixelScroll', function(evt) { // use wheelDeltaY evt.preventDefault(); ...});
Is there a reason why the grid needs to disable the browser's native scrolling? And if so, can I disable this?
— Reply to this email directly or view it on GitHub https://github.com/angular-ui/ng-grid/issues/1926#issuecomment-61464502.
Oh, thanks for the clarification. What I'm wondering about is why it has to call evt.preventDefault();. Most users find it very frustrating when the grid prevents them from scrolling the page especially when the grid takes the container's full width.
Yes, this is also my issue.
+1
+1 This is frustrating especially on mobile where the table takes up the full width and height of the screen. You can't scroll to anything below the table.
+1
In case it helps anyone, here's the code I added to fix this issue. It only prevents the page from scrolling when your mouse is in the grid and you haven't reached the top or bottom of the grid yet. I moved the evt.preventDefault() from here:
$elm.bind('wheel mousewheel DomMouseScroll MozMousePixelScroll', function(evt) {
// use wheelDeltaY
evt.preventDefault();
...
});
to:
$elm.bind('wheel mousewheel DomMouseScroll MozMousePixelScroll', function(evt) {
// use wheelDeltaY
var newEvent = GridUtil.normalizeWheelEvent(evt);
var args = { target: $elm };
if (newEvent.deltaY !== 0) {
var scrollYAmount = newEvent.deltaY * -120;
// Get the scroll percentage
var scrollYPercentage = (containerCtrl.viewport[0].scrollTop + scrollYAmount) / (rowContainer.getCanvasHeight() - rowContainer.getViewportHeight());
if ((newEvent.deltaY == -1 && scrollYPercentage < 1) || (newEvent.deltaY == 1 && scrollYPercentage > 0)) {
evt.preventDefault();
}
...
@jraadt Thanks for this. I'll take a look at implementing it. I'd be curious how it will affect scrolling within subgrids.
+1
I believe this is now resolved - could people verify?
It seems that this has been partially fixed. When scrolling up, the page continues scrolling when the grid's scroller reaches the top which is good. But the same doesn't happen when the grid's scroller is at the bottom. See 102 Sorting Also, I have noticed that grids don't have enough items to scroll still give issues with scrolling the page. See 101 Intro to UI-Grid
Interesting. Grids with little data such as the 101 tut allow the page to scroll downwards, but not upwards. Grids with more data such as 102 sorting allow the page to scroll upwards (when reaching the end of the scroll), but not downwards.
Thinking further on this, it could be the case that the grid decides whether to scroll itself or propagate to the parent based on how far through the grid scroll it currently is. If it's 100% and you scroll down, it propagates to the page. If you're at 0% and you scroll up, it propagates to the page.
So, when you have a grid with less than a page of data, it's always at 100% scroll. So it won't propagate the scroll up to the page. And currently we have a miscalculation on the vertical scroll so that when you reach the end of the data, you're not at 100% scroll. So when you have more than a page of data, currently you maybe cannot get to 100% so that it propagates the scroll down to the parent.
A theory at this stage, no more.
I'm also getting this problem. I've set the grid to be as tall as needed. We don't want the grid to be scrolling, only the page as a whole. However, whenever the mouse is over the grid, it disabled the whole page scrolling even if the grid itself doesn't scroll any.
OK, my theory on it not getting to 100% scroll is incorrect, it's a rendering glitch rather than a logic glitch. That is to say, the scroll bar on my Mac doesn't go all the way to the bottom, but if you look closely it's going all the way to the end of the scroll - perhaps it's leaving space for the horizontal to slide in underneath it?
I can resolve the scrolling on a grid with little data (no scrollbars) by commenting out the preventDefault in ui-grid-render-container.js (about line 156), and it appears to have no impact on anything else. With the larger grids with scrollbars, I can cause scrolling off the bottom if I "throw" it hard enough, so I still think there's some sort of calculation issue in there.
EDIT: it does have an ill-effect - it makes the scrolling "janky" - and so when you scroll using mousewheel quite fast, you get a bit of parent scroll as well as grid scroll. But I can fix the small datasets in another way, by checking scrollTop, in or about the same line of code.
But I still can't sort the scrolling off the bottom. It's not hitting the preventDefault, so that's not the cause of the issue. And if your mouse is over the header, then it does propagate (somewhat) to the page, but if over the body it doesn't. That's also weird.
On a crazy hunch, I looked at the pinning tutorial. If you have a pinned left and a pinned right, it propagates fine. If only a body, it doesn't. More accurately, it works if you scroll over the container without a scrollbar - so if you have a right container, then scrolling on body or left container will propagate. If you have no right container, then only scrolling on the left container will propagate.
I'm not sure I can fix this, as it's kinda weird. @swalters may have some ideas. But hopefully I've given some pointers to a diagnosis. I'll commit the change for small grids to scroll.
Assigning back to @c0bra, where it was before I started playing with it...
+1 Same here , with RC19:
It seems that this has been partially fixed. When scrolling up, the page continues scrolling when the grid's scroller reaches the top which is good. But the same doesn't happen when the grid's scroller is at the bottom
The issue came back since this commit ( which actually tried to not broke it again) : https://github.com/angular-ui/ng-grid/commit/78a4b433b4f186a23a2ec35afe88660f8f361119#commitcomment-9873285
Also experiencing this on RC21.