Browse Source

Pull request #2397: KERNEL-10110 itemFormatter

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit '9c857280b3c37e140332d47d0c280db3d279153b':
  KERNAL-10110
es6
guy 3 years ago
parent
commit
e5a669f2f0
  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, verticalOverscanSize: 0,
scrollLeft: 0, scrollLeft: 0,
scrollTop: 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]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
var item = o.itemFormatter(o.items[datum.index], datum.index);
child = BI._lazyCreateWidget(BI.extend({ child = BI._lazyCreateWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: datum.width, width: datum.width,
height: datum.height height: datum.height
}, o.items[datum.index], { }, item, {
cls: (o.items[datum.index].cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""), cls: (item.cls || "") + " collection-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
_left: datum.x, _left: datum.x,
_top: datum.y _top: datum.y
})); }));

10
src/base/grid/grid.js

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

9
src/base/list/listview.js

@ -13,7 +13,10 @@ BI.ListView = BI.inherit(BI.Widget, {
blockSize: 10, blockSize: 10,
scrollTop: 0, scrollTop: 0,
el: {}, 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) { while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); 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; var addedHeight = getElementHeight() - lastHeight;
this.cache[cnt] = { this.cache[cnt] = {
index: index, index: index,

17
src/base/list/virtualgrouplist.js

@ -13,7 +13,10 @@ BI.VirtualGroupList = BI.inherit(BI.Widget, {
blockSize: 10, blockSize: 10,
scrollTop: 0, scrollTop: 0,
rowHeight: "auto", 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) { while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); 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; var addedHeight = getElementHeight() - lastHeight;
this.tree.set(cnt, addedHeight); this.tree.set(cnt, addedHeight);
this.renderedIndex = cnt; 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.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 { } else {
for (var i = (start < 0 ? 0 : start); i <= end; i++) { for (var i = (start < 0 ? 0 : start); i <= end; i++) {
var index = i * o.blockSize; 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.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, overscanHeight: 100,
blockSize: 10, blockSize: 10,
scrollTop: 0, 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) { while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
var items = o.items.slice(index, index + o.blockSize); 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; var addedHeight = getElementHeight() - lastHeight;
this.tree.set(cnt, addedHeight); this.tree.set(cnt, addedHeight);
this.renderedIndex = cnt; this.renderedIndex = cnt;
@ -128,7 +133,7 @@ BI.VirtualList = BI.inherit(BI.Widget, {
} }
if (this.cache[i].destroyed === true) { if (this.cache[i].destroyed === true) {
for (var j = index; j < index + o.blockSize && j < o.items.length; j++) { 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); needMount.push(w);
currentFragment.appendChild(w.element[0]); currentFragment.appendChild(w.element[0]);
} }

Loading…
Cancel
Save