Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow properly scrolling when grid has autoheight and OnDemand collection #1087

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 44 additions & 7 deletions OnDemandList.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,8 @@ define([

postCreate: function () {
this.inherited(arguments);
var self = this;
// check visibility on scroll events
on(this.bodyNode, 'scroll',
miscUtil[this.pagingMethod](function (event) {
self._processScroll(event);
}, null, this.pagingDelay)
);
this._scrollEvent();
},

destroy: function () {
Expand Down Expand Up @@ -329,6 +324,29 @@ define([
},

lastScrollTop: 0,
_hasAutoHeight: function () {
return this._class && this._class.indexOf('dgrid-autoheight') >= 0;
},
_setClass: function () {
var before = this._hasAutoHeight();
this.inherited(arguments);
if (before !== this._hasAutoHeight()) //relink event
this._scrollEvent();
},
_scrollSignal: undefined,
_scrollEvent: function () {
var self = this;
if (this._scrollSignal)
this._scrollSignal.remove();
var node = this.bodyNode;
if (this._hasAutoHeight())
node = this.params.parentNode || window;
this._scrollSignal = on(node, 'scroll',
miscUtil[this.pagingMethod](function (event) {
self._processScroll(event);
}, null, this.pagingDelay)
);
},
_processScroll: function (evt) {
// summary:
// Checks to make sure that everything in the viewable area has been
Expand All @@ -345,7 +363,26 @@ define([
// References related to emitting dgrid-refresh-complete if applicable
lastRows,
preloadSearchNext = true;


if (this._hasAutoHeight()){
var parentNode = this.params.parentNode||window;
var cumulativeOffset = function(element,parent) {
var top = 0, left = 0;
do {
top += element.offsetTop || 0;
left += element.offsetLeft || 0;
element = element.offsetParent;
if (element == parent)
break;
} while(element);
return {
top: top,
left: left
};
};
visibleTop = Math.max(0,parentNode.scrollY - cumulativeOffset(scrollNode,parentNode).top);
visibleBottom = parentNode.innerHeight + visibleTop;
}
// XXX: I do not know why this happens.
// munging the actual location of the viewport relative to the preload node by a few pixels in either
// direction is necessary because at least WebKit on Windows seems to have an error that causes it to
Expand Down