Browse Source

grid优化

es6
guy 3 years ago
parent
commit
4142ceb03c
  1. 6
      src/base/collection/collection.js
  2. 25
      src/base/grid/grid.js

6
src/base/collection/collection.js

@ -279,15 +279,15 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (o.items.length > 0) { if (o.items.length > 0) {
this.container.setWidth(this._width); this.container.setWidth(this._width);
this.container.setHeight(this._height); this.container.setHeight(this._height);
this._debounceRelease();
this._calculateChildrenToRender();
// 元素未挂载时不能设置scrollTop // 元素未挂载时不能设置scrollTop
try { try {
this.element.scrollTop(o.scrollTop); this.element.scrollTop(o.scrollTop);
this.element.scrollLeft(o.scrollLeft); this.element.scrollLeft(o.scrollLeft);
} catch (e) { } catch (e) {
} }
this._debounceRelease();
this._calculateChildrenToRender();
} }
}, },

25
src/base/grid/grid.js

@ -74,20 +74,17 @@ BI.GridView = BI.inherit(BI.Widget, {
_calculateSizeAndPositionData: function () { _calculateSizeAndPositionData: function () {
var o = this.options; var o = this.options;
this.columnCount = 0;
this.rowCount = 0; this.rowCount = 0;
if (BI.isNumber(o.columnCount)) { if (BI.isNumber(o.columnCount)) {
this.columnCount = o.columnCount;
} else if (o.items.length > 0) { } else if (o.items.length > 0) {
this.columnCount = o.items[0].length; this.options.columnCount = o.items[0].length;
} }
if (BI.isNumber(o.rowCount)) { if (BI.isNumber(o.rowCount)) {
this.rowCount = o.rowCount;
} else { } else {
this.rowCount = o.items.length; this.options.rowCount = o.items.length;
} }
this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.columnCount, o.columnWidthGetter, o.estimatedColumnSize); this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(o.columnCount, o.columnWidthGetter, o.estimatedColumnSize);
this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.rowCount, o.rowHeightGetter, o.estimatedRowSize); this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(o.rowCount, o.rowHeightGetter, o.estimatedRowSize);
}, },
_getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) { _getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) {
@ -119,9 +116,9 @@ BI.GridView = BI.inherit(BI.Widget, {
this._renderedRowStartIndex = visibleRowIndices.start; this._renderedRowStartIndex = visibleRowIndices.start;
this._renderedRowStopIndex = visibleRowIndices.stop; 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 columnStartIndex = overscanColumnIndices.overscanStartIndex;
var columnStopIndex = overscanColumnIndices.overscanStopIndex; var columnStopIndex = overscanColumnIndices.overscanStopIndex;
@ -248,11 +245,11 @@ BI.GridView = BI.inherit(BI.Widget, {
}, },
_getContainerWidth: function () { _getContainerWidth: function () {
return this.columnCount * this.options.estimatedColumnSize; return this.options.columnCount * this.options.estimatedColumnSize;
}, },
_getContainerHeight: function () { _getContainerHeight: function () {
return this.rowCount * this.options.estimatedRowSize; return this.options.rowCount * this.options.estimatedRowSize;
}, },
_populate: function (items) { _populate: function (items) {
@ -265,15 +262,15 @@ BI.GridView = BI.inherit(BI.Widget, {
if (o.items.length > 0) { if (o.items.length > 0) {
this.container.setWidth(this._getContainerWidth()); this.container.setWidth(this._getContainerWidth());
this.container.setHeight(this._getContainerHeight()); this.container.setHeight(this._getContainerHeight());
this._debounceRelease();
this._calculateChildrenToRender();
// 元素未挂载时不能设置scrollTop // 元素未挂载时不能设置scrollTop
try { try {
this.element.scrollTop(o.scrollTop); this.element.scrollTop(o.scrollTop);
this.element.scrollLeft(o.scrollLeft); this.element.scrollLeft(o.scrollLeft);
} catch (e) { } catch (e) {
} }
this._debounceRelease();
this._calculateChildrenToRender();
} }
}, },

Loading…
Cancel
Save