Browse Source

表格性能优化

master
guy 7 years ago
parent
commit
7cd76678a2
  1. 45
      bi/base.js
  2. 45
      dist/base.js
  3. 45
      dist/bundle.js
  4. 20
      src/base/collection/collection.js
  5. 25
      src/base/grid/grid.js

45
bi/base.js

@ -2796,7 +2796,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -2824,9 +2824,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child;
if (index > -1) {
if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
@ -2881,34 +2881,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedKeys.push(datum.index);
renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child;
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[1]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[1]])
});
this.container.addItems(addedItems);
//拦截父子级关系
@ -14975,19 +14975,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return;
}
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex];
var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child;
if (index > -1) {
if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size);
@ -15029,35 +15029,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[count++] = child;
renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count] = child;
count++;
}
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[2]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[2]])
});
this.container.addItems(addedItems);
//拦截父子级关系

45
dist/base.js vendored

@ -2796,7 +2796,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -2824,9 +2824,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child;
if (index > -1) {
if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
@ -2881,34 +2881,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedKeys.push(datum.index);
renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child;
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[1]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[1]])
});
this.container.addItems(addedItems);
//拦截父子级关系
@ -14975,19 +14975,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return;
}
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex];
var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child;
if (index > -1) {
if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size);
@ -15029,35 +15029,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[count++] = child;
renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count] = child;
count++;
}
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[2]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[2]])
});
this.container.addItems(addedItems);
//拦截父子级关系

45
dist/bundle.js vendored

@ -31667,7 +31667,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -31695,9 +31695,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child;
if (index > -1) {
if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
@ -31752,34 +31752,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedKeys.push(datum.index);
renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child;
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[1]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[1]])
});
this.container.addItems(addedItems);
//拦截父子级关系
@ -43846,19 +43846,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return;
}
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex];
var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child;
if (index > -1) {
if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size);
@ -43900,35 +43900,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[count++] = child;
renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count] = child;
count++;
}
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[2]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[2]])
});
this.container.addItems(addedItems);
//拦截父子级关系

20
src/base/collection/collection.js

@ -127,7 +127,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return;
}
var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
//存储所有的left和top
var lefts = {}, tops = {};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
@ -155,9 +155,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
};
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
var child;
if (index > -1) {
if (index >= 0) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
this.renderedCells[index].el.setWidth(datum.width);
@ -212,34 +212,34 @@ BI.CollectionView = BI.inherit(BI.Widget, {
bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
renderedKeys.push(datum.index);
renderedKeys[datum.index] = [datum.index, i];
renderedWidgets[i] = child;
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[1]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[1]])
});
this.container.addItems(addedItems);
//拦截父子级关系

25
src/base/grid/grid.js

@ -121,19 +121,19 @@ BI.GridView = BI.inherit(BI.Widget, {
return;
}
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
var key = [rowIndex, columnIndex];
var key = rowIndex + "-" + columnIndex;
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var index = this.renderedKeys[key] && this.renderedKeys[key][2];
var child;
if (index > -1) {
if (index >= 0) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
this.renderedCells[index].el.setWidth(columnDatum.size);
@ -175,35 +175,36 @@ BI.GridView = BI.inherit(BI.Widget, {
maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[count++] = child;
renderedKeys[key] = [rowIndex, columnIndex, count];
renderedWidgets[count] = child;
count++;
}
}
//已存在的, 需要添加的和需要删除的
var existSet = {}, addSet = {}, deleteArray = [];
BI.each(renderedKeys, function (i, key) {
if (BI.deepContains(self.renderedKeys, key)) {
if (self.renderedKeys[i]) {
existSet[i] = key;
} else {
addSet[i] = key;
}
});
BI.each(this.renderedKeys, function (i, key) {
if (BI.deepContains(existSet, key)) {
if (existSet[i]) {
return;
}
if (BI.deepContains(addSet, key)) {
if (addSet[i]) {
return;
}
deleteArray.push(i);
deleteArray.push(key[2]);
});
BI.each(deleteArray, function (i, index) {
//性能优化,不调用destroy方法防止触发destroy事件
self.renderedCells[index].el._destroy();
});
var addedItems = [];
BI.each(addSet, function (index) {
addedItems.push(renderedCells[index])
BI.each(addSet, function (index, key) {
addedItems.push(renderedCells[key[2]])
});
this.container.addItems(addedItems);
//拦截父子级关系

Loading…
Cancel
Save