From 4142ceb03c777031af440d9f18da5e2924a1341f Mon Sep 17 00:00:00 2001 From: guy Date: Wed, 22 Sep 2021 18:02:23 +0800 Subject: [PATCH] =?UTF-8?q?grid=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/base/collection/collection.js | 6 +++--- src/base/grid/grid.js | 25 +++++++++++-------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/base/collection/collection.js b/src/base/collection/collection.js index 1167801bd..804e5c6fd 100644 --- a/src/base/collection/collection.js +++ b/src/base/collection/collection.js @@ -279,15 +279,15 @@ BI.CollectionView = BI.inherit(BI.Widget, { if (o.items.length > 0) { this.container.setWidth(this._width); this.container.setHeight(this._height); - - this._debounceRelease(); - this._calculateChildrenToRender(); // 元素未挂载时不能设置scrollTop try { this.element.scrollTop(o.scrollTop); this.element.scrollLeft(o.scrollLeft); } catch (e) { } + + this._debounceRelease(); + this._calculateChildrenToRender(); } }, diff --git a/src/base/grid/grid.js b/src/base/grid/grid.js index 07f0a7fa3..6d489cf34 100644 --- a/src/base/grid/grid.js +++ b/src/base/grid/grid.js @@ -74,20 +74,17 @@ BI.GridView = BI.inherit(BI.Widget, { _calculateSizeAndPositionData: function () { var o = this.options; - this.columnCount = 0; this.rowCount = 0; if (BI.isNumber(o.columnCount)) { - this.columnCount = o.columnCount; } else if (o.items.length > 0) { - this.columnCount = o.items[0].length; + this.options.columnCount = o.items[0].length; } if (BI.isNumber(o.rowCount)) { - this.rowCount = o.rowCount; } else { - this.rowCount = o.items.length; + this.options.rowCount = o.items.length; } - this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.columnCount, o.columnWidthGetter, o.estimatedColumnSize); - this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.rowCount, o.rowHeightGetter, o.estimatedRowSize); + this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(o.columnCount, o.columnWidthGetter, o.estimatedColumnSize); + this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(o.rowCount, o.rowHeightGetter, o.estimatedRowSize); }, _getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) { @@ -119,9 +116,9 @@ BI.GridView = BI.inherit(BI.Widget, { this._renderedRowStartIndex = visibleRowIndices.start; this._renderedRowStopIndex = visibleRowIndices.stop; - var overscanColumnIndices = this._getOverscanIndices(this.columnCount, overscanColumnCount, this._renderedColumnStartIndex, this._renderedColumnStopIndex); + var overscanColumnIndices = this._getOverscanIndices(o.columnCount, overscanColumnCount, this._renderedColumnStartIndex, this._renderedColumnStopIndex); - var overscanRowIndices = this._getOverscanIndices(this.rowCount, overscanRowCount, this._renderedRowStartIndex, this._renderedRowStopIndex); + var overscanRowIndices = this._getOverscanIndices(o.rowCount, overscanRowCount, this._renderedRowStartIndex, this._renderedRowStopIndex); var columnStartIndex = overscanColumnIndices.overscanStartIndex; var columnStopIndex = overscanColumnIndices.overscanStopIndex; @@ -248,11 +245,11 @@ BI.GridView = BI.inherit(BI.Widget, { }, _getContainerWidth: function () { - return this.columnCount * this.options.estimatedColumnSize; + return this.options.columnCount * this.options.estimatedColumnSize; }, _getContainerHeight: function () { - return this.rowCount * this.options.estimatedRowSize; + return this.options.rowCount * this.options.estimatedRowSize; }, _populate: function (items) { @@ -265,15 +262,15 @@ BI.GridView = BI.inherit(BI.Widget, { if (o.items.length > 0) { this.container.setWidth(this._getContainerWidth()); this.container.setHeight(this._getContainerHeight()); - - this._debounceRelease(); - this._calculateChildrenToRender(); // 元素未挂载时不能设置scrollTop try { this.element.scrollTop(o.scrollTop); this.element.scrollLeft(o.scrollLeft); } catch (e) { } + + this._debounceRelease(); + this._calculateChildrenToRender(); } },