Maintain scrollTop when changing item count
parent
70488eeb8e
commit
3cad0959e6
15
treegrid.js
15
treegrid.js
|
@ -470,8 +470,6 @@ TreeGrid.prototype.syncView = function()
|
|||
{
|
||||
if (!this.table.offsetParent)
|
||||
return;
|
||||
var scrollPos = this.tableWrapper.scrollHeight > this.tableWrapper.offsetHeight ?
|
||||
this.tableWrapper.scrollTop / (this.tableWrapper.scrollHeight - this.tableWrapper.offsetHeight) : 0;
|
||||
var offsetHeight = this.wrapper.offsetHeight - this.thead.offsetHeight;
|
||||
var visibleItems = Math.ceil(offsetHeight/this.minItemHeight);
|
||||
var endStart = this.nodeCount - visibleItems;
|
||||
|
@ -486,6 +484,12 @@ TreeGrid.prototype.syncView = function()
|
|||
{
|
||||
// Calculate virtual scroll
|
||||
var lastFirst = endStart+this._findVisibleNodeOffset(lastNodes, offsetHeight);
|
||||
var avgItemHeight = this.endItemHeight / lastNodes.length;
|
||||
avgItemHeight = (avgItemHeight < this.minItemHeight ? this.minItemHeight : avgItemHeight);
|
||||
var scrollPos = this.nodeCount*avgItemHeight > this.tableWrapper.offsetHeight ?
|
||||
this.tableWrapper.scrollTop / (this.nodeCount*avgItemHeight - this.tableWrapper.offsetHeight) : 0;
|
||||
if (scrollPos > 1)
|
||||
scrollPos = 1;
|
||||
var firstVisible = scrollPos*lastFirst;
|
||||
var rangeStart = Math.floor(firstVisible);
|
||||
var rangeCount = visibleItems;
|
||||
|
@ -510,10 +514,7 @@ TreeGrid.prototype.syncView = function()
|
|||
var visibleNodes = this._findNodes(this.root, rangeStart, rangeCount);
|
||||
this._renderNodes(visibleNodes);
|
||||
this._syncStart(visibleNodes);
|
||||
if (endStart > rangeStart+rangeCount)
|
||||
{
|
||||
this._addPlaceholder('mid', 0);
|
||||
}
|
||||
this._addPlaceholder('mid');
|
||||
firstItemHeight = getNodeHeight(visibleNodes[0])*(firstVisible-rangeStart);
|
||||
}
|
||||
this._setPlaceholder('top', this.tableWrapper.scrollTop-firstItemHeight);
|
||||
|
@ -546,8 +547,6 @@ TreeGrid.prototype.syncView = function()
|
|||
}
|
||||
if (endStart > 0)
|
||||
{
|
||||
var avgItemHeight = this.endItemHeight / lastNodes.length;
|
||||
avgItemHeight = (avgItemHeight < this.minItemHeight ? this.minItemHeight : avgItemHeight);
|
||||
this._setPlaceholder('mid', this.nodeCount*avgItemHeight - total - (this.tableWrapper.scrollTop-firstItemHeight));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue