|
|
|
/**
|
|
|
|
* 预览表
|
|
|
|
*
|
|
|
|
* Created by GUY on 2015/12/25.
|
|
|
|
* @class BI.PreviewTable
|
|
|
|
* @extends BI.Widget
|
|
|
|
*/
|
|
|
|
BI.PreviewTable = BI.inherit(BI.Widget, {
|
|
|
|
|
|
|
|
_defaultConfig: function () {
|
|
|
|
return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), {
|
|
|
|
baseCls: "bi-preview-table",
|
|
|
|
isNeedFreeze: false,
|
|
|
|
freezeCols: [],
|
|
|
|
rowSize: null,
|
|
|
|
columnSize: [],
|
|
|
|
headerRowSize: 30,
|
|
|
|
header: [],
|
|
|
|
items: []
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_init: function () {
|
|
|
|
BI.PreviewTable.superclass._init.apply(this, arguments);
|
|
|
|
var self = this, o = this.options;
|
|
|
|
|
|
|
|
this.table = BI.createWidget({
|
|
|
|
type: "bi.table_view",
|
|
|
|
element: this,
|
|
|
|
isNeedResize: false,
|
|
|
|
|
|
|
|
isResizeAdapt: false,
|
|
|
|
|
|
|
|
isNeedFreeze: o.isNeedFreeze,
|
|
|
|
freezeCols: o.freezeCols,
|
|
|
|
|
|
|
|
rowSize: o.rowSize,
|
|
|
|
columnSize: o.columnSize,
|
|
|
|
headerRowSize: o.headerRowSize,
|
|
|
|
|
|
|
|
header: BI.map(o.header, function (i, items) {
|
|
|
|
return BI.map(items, function (j, item) {
|
|
|
|
return BI.extend({
|
|
|
|
type: "bi.preview_table_header_cell"
|
|
|
|
}, item);
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
items: BI.map(o.items, function (i, items) {
|
|
|
|
return BI.map(items, function (j, item) {
|
|
|
|
return BI.extend({
|
|
|
|
type: "bi.preview_table_cell"
|
|
|
|
}, item);
|
|
|
|
});
|
|
|
|
})
|
|
|
|
});
|
|
|
|
this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () {
|
|
|
|
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments);
|
|
|
|
});
|
|
|
|
this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () {
|
|
|
|
self._adjustColumns();
|
|
|
|
});
|
|
|
|
this._adjustColumns();
|
|
|
|
},
|
|
|
|
|
|
|
|
// 是否有自适应调节的列,即列宽为""
|
|
|
|
_hasAdaptCol: function (columnSize) {
|
|
|
|
return BI.any(columnSize, function (i, size) {
|
|
|
|
return size === "";
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
_isPercentage: function (columnSize) {
|
|
|
|
return columnSize[0] <= 1;
|
|
|
|
},
|
|
|
|
|
|
|
|
_adjustColumns: function () {
|
|
|
|
var self = this, o = this.options;
|
|
|
|
if (o.isNeedFreeze === true) {
|
|
|
|
// 如果存在百分比的情况
|
|
|
|
if (this._isPercentage(o.columnSize)) {
|
|
|
|
if (this._hasAdaptCol(o.columnSize)) {
|
|
|
|
var findCols = [], remain = 0;
|
|
|
|
BI.each(o.columnSize, function (i, size) {
|
|
|
|
if (size === "") {
|
|
|
|
findCols.push(i);
|
|
|
|
} else {
|
|
|
|
remain += size;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
remain = 1 - remain;
|
|
|
|
var average = remain / findCols.length;
|
|
|
|
BI.each(findCols, function (i, col) {
|
|
|
|
o.columnSize[col] = average;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
var isRight = BI.first(o.freezeCols) !== 0;
|
|
|
|
var freezeSize = [], notFreezeSize = [];
|
|
|
|
BI.each(o.columnSize, function (i, size) {
|
|
|
|
if (o.freezeCols.contains(i)) {
|
|
|
|
freezeSize.push(size);
|
|
|
|
} else {
|
|
|
|
notFreezeSize.push(size);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize);
|
|
|
|
BI.each(freezeSize, function (i, size) {
|
|
|
|
freezeSize[i] = size / sumFreezeSize;
|
|
|
|
});
|
|
|
|
BI.each(notFreezeSize, function (i, size) {
|
|
|
|
notFreezeSize[i] = size / sumNotFreezeSize;
|
|
|
|
});
|
|
|
|
this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]);
|
|
|
|
this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize)));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100%
|
|
|
|
if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) {
|
|
|
|
this.table.setRegionColumnSize(["100%"]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
setColumnSize: function (columnSize) {
|
|
|
|
return this.table.setColumnSize(columnSize);
|
|
|
|
},
|
|
|
|
|
|
|
|
getColumnSize: function () {
|
|
|
|
return this.table.getColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getCalculateColumnSize: function () {
|
|
|
|
return this.table.getCalculateColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
setHeaderColumnSize: function (columnSize) {
|
|
|
|
return this.table.setHeaderColumnSize(columnSize);
|
|
|
|
},
|
|
|
|
|
|
|
|
setRegionColumnSize: function (columnSize) {
|
|
|
|
return this.table.setRegionColumnSize(columnSize);
|
|
|
|
},
|
|
|
|
|
|
|
|
getRegionColumnSize: function () {
|
|
|
|
return this.table.getRegionColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getCalculateRegionColumnSize: function () {
|
|
|
|
return this.table.getCalculateRegionColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getCalculateRegionRowSize: function () {
|
|
|
|
return this.table.getCalculateRegionRowSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getClientRegionColumnSize: function () {
|
|
|
|
return this.table.getClientRegionColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getScrollRegionColumnSize: function () {
|
|
|
|
return this.table.getScrollRegionColumnSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
getScrollRegionRowSize: function () {
|
|
|
|
return this.table.getScrollRegionRowSize();
|
|
|
|
},
|
|
|
|
|
|
|
|
hasVerticalScroll: function () {
|
|
|
|
return this.table.hasVerticalScroll();
|
|
|
|
},
|
|
|
|
|
|
|
|
setVerticalScroll: function (scrollTop) {
|
|
|
|
return this.table.setVerticalScroll(scrollTop);
|
|
|
|
},
|
|
|
|
|
|
|
|
setLeftHorizontalScroll: function (scrollLeft) {
|
|
|
|
return this.table.setLeftHorizontalScroll(scrollLeft);
|
|
|
|
},
|
|
|
|
|
|
|
|
setRightHorizontalScroll: function (scrollLeft) {
|
|
|
|
return this.table.setRightHorizontalScroll(scrollLeft);
|
|
|
|
},
|
|
|
|
|
|
|
|
getVerticalScroll: function () {
|
|
|
|
return this.table.getVerticalScroll();
|
|
|
|
},
|
|
|
|
|
|
|
|
getLeftHorizontalScroll: function () {
|
|
|
|
return this.table.getLeftHorizontalScroll();
|
|
|
|
},
|
|
|
|
|
|
|
|
getRightHorizontalScroll: function () {
|
|
|
|
return this.table.getRightHorizontalScroll();
|
|
|
|
},
|
|
|
|
|
|
|
|
getColumns: function () {
|
|
|
|
return this.table.getColumns();
|
|
|
|
},
|
|
|
|
|
|
|
|
populate: function (items, header) {
|
|
|
|
if (items) {
|
|
|
|
items = BI.map(items, function (i, items) {
|
|
|
|
return BI.map(items, function (j, item) {
|
|
|
|
return BI.extend({
|
|
|
|
type: "bi.preview_table_cell"
|
|
|
|
}, item);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (header) {
|
|
|
|
header = BI.map(header, function (i, items) {
|
|
|
|
return BI.map(items, function (j, item) {
|
|
|
|
return BI.extend({
|
|
|
|
type: "bi.preview_table_header_cell"
|
|
|
|
}, item);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.table.populate(items, header);
|
|
|
|
this._adjustColumns();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE";
|
|
|
|
BI.shortcut("bi.preview_table", BI.PreviewTable);
|