Browse Source

KERNAL-10110

es6
guy 3 years ago
parent
commit
9c857280b3
  1. 10
      src/base/collection/collection.js
  2. 10
      src/base/grid/grid.js
  3. 9
      src/base/list/listview.js
  4. 17
      src/base/list/virtualgrouplist.js
  5. 11
      src/base/list/virtuallist.js

10
src/base/collection/collection.js

@ -18,7 +18,10 @@ BI.CollectionView = BI.inherit(BI.Widget, {
verticalOverscanSize: 0,
scrollLeft: 0,
scrollTop: 0,
items: []
items: [],
itemFormatter: function (item, index) {
return item;
}
});
},
@ -176,12 +179,13 @@ BI.CollectionView = BI.inherit(BI.Widget, {
// }
renderedCells.push(child = this.renderedCells[index]);
} else {
var item = o.itemFormatter(o.items[datum.index], datum.index);
child = BI._lazyCreateWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
}, o.items[datum.index], {
cls: (o.items[datum.index].cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
}, item, {
cls: (item.cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x,
_top: datum.y
}));

10
src/base/grid/grid.js

@ -21,7 +21,10 @@ BI.GridView = BI.inherit(BI.Widget, {
// estimatedRowSize: 30, //rowHeightGetter为function时必设
scrollLeft: 0,
scrollTop: 0,
items: []
items: [],
itemFormatter: function (item, row, col) {
return item;
}
});
},
@ -172,12 +175,13 @@ BI.GridView = BI.inherit(BI.Widget, {
child = this.renderedCells[index].el;
renderedCells.push(this.renderedCells[index]);
} else {
var item = o.itemFormatter(o.items[rowIndex][columnIndex], rowIndex, columnIndex);
child = BI._lazyCreateWidget(BI.extend({
type: "bi.label",
width: columnDatum.size,
height: rowDatum.size
}, o.items[rowIndex][columnIndex], {
cls: (o.items[rowIndex][columnIndex].cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""),
}, item, {
cls: (item.cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""),
_rowIndex: rowIndex,
_columnIndex: columnIndex,
_left: columnDatum.offset + horizontalOffsetAdjustment,

9
src/base/list/listview.js

@ -13,7 +13,10 @@ BI.ListView = BI.inherit(BI.Widget, {
blockSize: 10,
scrollTop: 0,
el: {},
items: []
items: [],
itemFormatter: function (item, index) {
return item;
}
};
},
@ -71,7 +74,9 @@ BI.ListView = BI.inherit(BI.Widget, {
};
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize);
this.container.addItems(items, this);
this.container.addItems(items.map(function (item, i) {
return o.itemFormatter(item, index + i);
}), this);
var addedHeight = getElementHeight() - lastHeight;
this.cache[cnt] = {
index: index,

17
src/base/list/virtualgrouplist.js

@ -13,7 +13,10 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
blockSize: 10,
scrollTop: 0,
rowHeight: "auto",
items: []
items: [],
itemFormatter: function (item, index) {
return item;
}
};
},
@ -79,7 +82,9 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
};
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize);
this.container.addItems(items, this);
this.container.addItems(items.map(function (item, i) {
return o.itemFormatter(item, index + i)
}), this);
var addedHeight = getElementHeight() - lastHeight;
this.tree.set(cnt, addedHeight);
this.renderedIndex = cnt;
@ -107,7 +112,9 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
}
}
this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - this.tree.sumTo(Math.min(end, this.renderedIndex)));
this.container.populate(items);
this.container.populate(items.map(function (item, i) {
return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i)
}));
} else {
for (var i = (start < 0 ? 0 : start); i <= end; i++) {
var index = i * o.blockSize;
@ -116,7 +123,9 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
}
}
this.container.element.height(o.rowHeight * o.items.length - topHeight);
this.container.populate(items);
this.container.populate(items.map(function (item, i) {
return o.itemFormatter(item, (start < 0 ? 0 : start) * o.blockSize + i)
}));
}
},

11
src/base/list/virtuallist.js

@ -12,7 +12,10 @@ BI.VirtualList = BI.inherit(BI.Widget, {
overscanHeight: 100,
blockSize: 10,
scrollTop: 0,
items: []
items: [],
itemFormatter: function (item, index) {
return item;
}
};
},
@ -71,7 +74,9 @@ BI.VirtualList = BI.inherit(BI.Widget, {
};
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize);
this.container.addItems(items, this);
this.container.addItems(items.map(function (item, i) {
return o.itemFormatter(item, index + i)
}), this);
var addedHeight = getElementHeight() - lastHeight;
this.tree.set(cnt, addedHeight);
this.renderedIndex = cnt;
@ -128,7 +133,7 @@ BI.VirtualList = BI.inherit(BI.Widget, {
}
if (this.cache[i].destroyed === true) {
for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
var w = this.container._addElement(j, o.items[j], this);
var w = this.container._addElement(j, o.itemFormatter(o.items[j], j), this);
needMount.push(w);
currentFragment.appendChild(w.element[0]);
}

Loading…
Cancel
Save