forked from fanruan/fineui
Teller
7 years ago
19 changed files with 1585 additions and 1434 deletions
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -1,33 +1,36 @@ |
|||||||
/** |
/** |
||||||
* |
* |
||||||
* 表格 |
* 表格 |
||||||
* |
* |
||||||
* Created by GUY on 2015/9/22. |
* Created by GUY on 2015/9/22. |
||||||
* @class BI.TableCell |
* @class BI.TableCell |
||||||
* @extends BI.Single |
* @extends BI.Single |
||||||
*/ |
*/ |
||||||
BI.TableCell = BI.inherit(BI.Widget, { |
BI.TableCell = BI.inherit(BI.Widget, { |
||||||
_defaultConfig: function () { |
_defaultConfig: function () { |
||||||
return BI.extend(BI.TableCell.superclass._defaultConfig.apply(this, arguments), { |
return BI.extend(BI.TableCell.superclass._defaultConfig.apply(this, arguments), { |
||||||
baseCls: "bi-table-cell", |
baseCls: "bi-table-cell", |
||||||
textAlign: "left", |
textAlign: "left", |
||||||
text: "" |
text: "" |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_init: function () { |
_init: function () { |
||||||
BI.TableCell.superclass._init.apply(this, arguments); |
BI.TableCell.superclass._init.apply(this, arguments); |
||||||
BI.createWidget({ |
var o = this.options; |
||||||
type: "bi.label", |
BI.createWidget({ |
||||||
element: this, |
type: "bi.label", |
||||||
whiteSpace: "nowrap", |
element: this, |
||||||
textAlign: this.options.textAlign, |
whiteSpace: o.whiteSpace || "nowrap", |
||||||
height: this.options.height, |
textAlign: this.options.textAlign, |
||||||
text: this.options.text, |
height: this.options.height, |
||||||
value: this.options.value, |
text: this.options.text, |
||||||
lgap: 5 |
value: this.options.value, |
||||||
}); |
lgap: o.lgap, |
||||||
} |
rgap: o.rgap, |
||||||
}); |
hgap: o.hgap || 5 |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
BI.shortcut("bi.table_cell", BI.TableCell); |
BI.shortcut("bi.table_cell", BI.TableCell); |
@ -1,30 +1,34 @@ |
|||||||
/** |
/** |
||||||
* |
* |
||||||
* 表格 |
* 表格 |
||||||
* |
* |
||||||
* Created by GUY on 2015/9/22. |
* Created by GUY on 2015/9/22. |
||||||
* @class BI.TableHeaderCell |
* @class BI.TableHeaderCell |
||||||
* @extends BI.Single |
* @extends BI.Single |
||||||
*/ |
*/ |
||||||
BI.TableHeaderCell = BI.inherit(BI.Widget, { |
BI.TableHeaderCell = BI.inherit(BI.Widget, { |
||||||
_defaultConfig: function () { |
_defaultConfig: function () { |
||||||
return BI.extend(BI.TableHeaderCell.superclass._defaultConfig.apply(this, arguments), { |
return BI.extend(BI.TableHeaderCell.superclass._defaultConfig.apply(this, arguments), { |
||||||
baseCls: "bi-table-header-cell", |
baseCls: "bi-table-header-cell", |
||||||
text: "" |
text: "" |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_init: function () { |
_init: function () { |
||||||
BI.TableHeaderCell.superclass._init.apply(this, arguments); |
BI.TableHeaderCell.superclass._init.apply(this, arguments); |
||||||
BI.createWidget({ |
var o = this.options; |
||||||
type: "bi.label", |
BI.createWidget({ |
||||||
element: this, |
type: "bi.label", |
||||||
textAlign: "center", |
element: this, |
||||||
height: this.options.height, |
textAlign: o.textAlign || "center", |
||||||
text: this.options.text, |
height: this.options.height, |
||||||
value: this.options.value |
text: this.options.text, |
||||||
}); |
value: this.options.value, |
||||||
} |
lgap: o.lgap, |
||||||
}); |
rgap: o.rgap, |
||||||
|
hgap: o.hgap || 5 |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
|
|
||||||
BI.shortcut("bi.table_header_cell", BI.TableHeaderCell); |
BI.shortcut("bi.table_header_cell", BI.TableHeaderCell); |
@ -1,32 +1,35 @@ |
|||||||
/** |
/** |
||||||
* 预览表列 |
* 预览表列 |
||||||
* |
* |
||||||
* Created by GUY on 2015/12/25. |
* Created by GUY on 2015/12/25. |
||||||
* @class BI.PreviewTableCell |
* @class BI.PreviewTableCell |
||||||
* @extends BI.Widget |
* @extends BI.Widget |
||||||
*/ |
*/ |
||||||
BI.PreviewTableCell = BI.inherit(BI.Widget, { |
BI.PreviewTableCell = BI.inherit(BI.Widget, { |
||||||
|
|
||||||
_defaultConfig: function () { |
_defaultConfig: function () { |
||||||
return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { |
return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { |
||||||
baseCls: "bi-preview-table-cell", |
baseCls: "bi-preview-table-cell", |
||||||
text: "" |
text: "" |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_init: function () { |
_init: function () { |
||||||
BI.PreviewTableCell.superclass._init.apply(this, arguments); |
BI.PreviewTableCell.superclass._init.apply(this, arguments); |
||||||
var self = this, o = this.options; |
var self = this, o = this.options; |
||||||
|
|
||||||
BI.createWidget({ |
BI.createWidget({ |
||||||
type: "bi.label", |
type: "bi.label", |
||||||
element: this, |
element: this, |
||||||
textAlign: "left", |
textAlign: o.textAlign || "left", |
||||||
whiteSpace: "normal", |
whiteSpace: o.whiteSpace || "normal", |
||||||
height: this.options.height, |
height: this.options.height, |
||||||
text: this.options.text, |
text: this.options.text, |
||||||
value: this.options.value |
value: this.options.value, |
||||||
}); |
lgap: o.lgap, |
||||||
} |
rgap: o.rgap, |
||||||
}); |
hgap: o.hgap || 5 |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell); |
BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell); |
@ -1,32 +1,35 @@ |
|||||||
/** |
/** |
||||||
* 预览表 |
* 预览表 |
||||||
* |
* |
||||||
* Created by GUY on 2015/12/25. |
* Created by GUY on 2015/12/25. |
||||||
* @class BI.PreviewTableHeaderCell |
* @class BI.PreviewTableHeaderCell |
||||||
* @extends BI.Widget |
* @extends BI.Widget |
||||||
*/ |
*/ |
||||||
BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { |
BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { |
||||||
|
|
||||||
_defaultConfig: function () { |
_defaultConfig: function () { |
||||||
return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { |
return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { |
||||||
baseCls: "bi-preview-table-header-cell", |
baseCls: "bi-preview-table-header-cell", |
||||||
text: "" |
text: "" |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_init: function () { |
_init: function () { |
||||||
BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); |
BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); |
||||||
var self = this, o = this.options; |
var self = this, o = this.options; |
||||||
|
|
||||||
BI.createWidget({ |
BI.createWidget({ |
||||||
type: "bi.label", |
type: "bi.label", |
||||||
element: this, |
element: this, |
||||||
textAlign: "left", |
textAlign: o.textAlign || "left", |
||||||
whiteSpace: "normal", |
whiteSpace: o.whiteSpace || "normal", |
||||||
height: this.options.height, |
height: this.options.height, |
||||||
text: this.options.text, |
text: this.options.text, |
||||||
value: this.options.value |
value: this.options.value, |
||||||
}); |
lgap: o.lgap, |
||||||
} |
rgap: o.rgap, |
||||||
}); |
hgap: o.hgap || 5 |
||||||
|
}); |
||||||
|
} |
||||||
|
}); |
||||||
BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell); |
BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell); |
@ -1,205 +1,223 @@ |
|||||||
/** |
/** |
||||||
* 预览表 |
* 预览表 |
||||||
* |
* |
||||||
* Created by GUY on 2015/12/25. |
* Created by GUY on 2015/12/25. |
||||||
* @class BI.PreviewTable |
* @class BI.PreviewTable |
||||||
* @extends BI.Widget |
* @extends BI.Widget |
||||||
*/ |
*/ |
||||||
BI.PreviewTable = BI.inherit(BI.Widget, { |
BI.PreviewTable = BI.inherit(BI.Widget, { |
||||||
|
|
||||||
_defaultConfig: function () { |
_defaultConfig: function () { |
||||||
return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { |
return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { |
||||||
baseCls: "bi-preview-table", |
baseCls: "bi-preview-table", |
||||||
isNeedFreeze: false, |
isNeedFreeze: false, |
||||||
freezeCols: [], |
freezeCols: [], |
||||||
rowSize: null, |
rowSize: null, |
||||||
columnSize: [], |
columnSize: [], |
||||||
headerRowSize: 30, |
headerRowSize: 30, |
||||||
header: [], |
header: [], |
||||||
items: [] |
items: [] |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_init: function () { |
_init: function () { |
||||||
BI.PreviewTable.superclass._init.apply(this, arguments); |
BI.PreviewTable.superclass._init.apply(this, arguments); |
||||||
var self = this, o = this.options; |
var self = this, o = this.options; |
||||||
|
|
||||||
this.table = BI.createWidget({ |
this.table = BI.createWidget({ |
||||||
type: "bi.table_view", |
type: "bi.table_view", |
||||||
element: this, |
element: this, |
||||||
isNeedResize: false, |
isNeedResize: false, |
||||||
|
|
||||||
isResizeAdapt: false, |
isResizeAdapt: false, |
||||||
|
|
||||||
isNeedFreeze: o.isNeedFreeze, |
isNeedFreeze: o.isNeedFreeze, |
||||||
freezeCols: o.freezeCols, |
freezeCols: o.freezeCols, |
||||||
|
|
||||||
rowSize: o.rowSize, |
rowSize: o.rowSize, |
||||||
columnSize: o.columnSize, |
columnSize: o.columnSize, |
||||||
headerRowSize: o.headerRowSize, |
headerRowSize: o.headerRowSize, |
||||||
|
|
||||||
header: BI.map(o.header, function (i, items) { |
header: BI.map(o.header, function (i, items) { |
||||||
return BI.map(items, function (j, item) { |
return BI.map(items, function (j, item) { |
||||||
return BI.extend({ |
return BI.extend({ |
||||||
type: "bi.preview_table_header_cell" |
type: "bi.preview_table_header_cell" |
||||||
}, item); |
}, item); |
||||||
}); |
}); |
||||||
}), |
}), |
||||||
items: BI.map(o.items, function (i, items) { |
items: BI.map(o.items, function (i, items) { |
||||||
return BI.map(items, function (j, item) { |
return BI.map(items, function (j, item) { |
||||||
return BI.extend({ |
return BI.extend({ |
||||||
type: "bi.preview_table_cell" |
type: "bi.preview_table_cell" |
||||||
}, item); |
}, item); |
||||||
}); |
}); |
||||||
}) |
}) |
||||||
}); |
}); |
||||||
this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { |
this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { |
||||||
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); |
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); |
||||||
}); |
}); |
||||||
this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { |
this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { |
||||||
self._adjustColumns(); |
self._adjustColumns(); |
||||||
}); |
}); |
||||||
this._adjustColumns(); |
this._adjustColumns(); |
||||||
}, |
}, |
||||||
|
|
||||||
// 是否有自适应调节的列,即列宽为""
|
// 是否有自适应调节的列,即列宽为""
|
||||||
_hasAdaptCol: function (columnSize) { |
_hasAdaptCol: function (columnSize) { |
||||||
return BI.any(columnSize, function (i, size) { |
return BI.any(columnSize, function (i, size) { |
||||||
return size === ""; |
return size === ""; |
||||||
}); |
}); |
||||||
}, |
}, |
||||||
|
|
||||||
_isPercentage: function (columnSize) { |
_isPercentage: function (columnSize) { |
||||||
return columnSize[0] <= 1; |
return columnSize[0] <= 1; |
||||||
}, |
}, |
||||||
|
|
||||||
_adjustColumns: function () { |
_adjustColumns: function () { |
||||||
var self = this, o = this.options; |
var self = this, o = this.options; |
||||||
if (o.isNeedFreeze === true) { |
if (o.isNeedFreeze === true) { |
||||||
// 如果存在百分比的情况
|
// 如果存在百分比的情况
|
||||||
if (this._isPercentage(o.columnSize)) { |
if (this._isPercentage(o.columnSize)) { |
||||||
if (this._hasAdaptCol(o.columnSize)) { |
if (this._hasAdaptCol(o.columnSize)) { |
||||||
var findCols = [], remain = 0; |
var findCols = [], remain = 0; |
||||||
BI.each(o.columnSize, function (i, size) { |
BI.each(o.columnSize, function (i, size) { |
||||||
if (size === "") { |
if (size === "") { |
||||||
findCols.push(i); |
findCols.push(i); |
||||||
} else { |
} else { |
||||||
remain += size; |
remain += size; |
||||||
} |
} |
||||||
}); |
}); |
||||||
remain = 1 - remain; |
remain = 1 - remain; |
||||||
var average = remain / findCols.length; |
var average = remain / findCols.length; |
||||||
BI.each(findCols, function (i, col) { |
BI.each(findCols, function (i, col) { |
||||||
o.columnSize[col] = average; |
o.columnSize[col] = average; |
||||||
}); |
}); |
||||||
} |
} |
||||||
var isRight = BI.first(o.freezeCols) !== 0; |
var isRight = BI.first(o.freezeCols) !== 0; |
||||||
var freezeSize = [], notFreezeSize = []; |
var freezeSize = [], notFreezeSize = []; |
||||||
BI.each(o.columnSize, function (i, size) { |
BI.each(o.columnSize, function (i, size) { |
||||||
if (o.freezeCols.contains(i)) { |
if (o.freezeCols.contains(i)) { |
||||||
freezeSize.push(size); |
freezeSize.push(size); |
||||||
} else { |
} else { |
||||||
notFreezeSize.push(size); |
notFreezeSize.push(size); |
||||||
} |
} |
||||||
}); |
}); |
||||||
var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); |
var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); |
||||||
BI.each(freezeSize, function (i, size) { |
BI.each(freezeSize, function (i, size) { |
||||||
freezeSize[i] = size / sumFreezeSize; |
freezeSize[i] = size / sumFreezeSize; |
||||||
}); |
}); |
||||||
BI.each(notFreezeSize, function (i, size) { |
BI.each(notFreezeSize, function (i, size) { |
||||||
notFreezeSize[i] = size / sumNotFreezeSize; |
notFreezeSize[i] = size / sumNotFreezeSize; |
||||||
}); |
}); |
||||||
this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); |
this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); |
||||||
this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); |
this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); |
||||||
} |
} |
||||||
} else { |
} else { |
||||||
// 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100%
|
// 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100%
|
||||||
if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { |
if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { |
||||||
this.table.setRegionColumnSize(["100%"]); |
this.table.setRegionColumnSize(["100%"]); |
||||||
} |
} |
||||||
} |
} |
||||||
}, |
}, |
||||||
|
|
||||||
setColumnSize: function (columnSize) { |
setColumnSize: function (columnSize) { |
||||||
return this.table.setColumnSize(columnSize); |
return this.table.setColumnSize(columnSize); |
||||||
}, |
}, |
||||||
|
|
||||||
getColumnSize: function () { |
getColumnSize: function () { |
||||||
return this.table.getColumnSize(); |
return this.table.getColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getCalculateColumnSize: function () { |
getCalculateColumnSize: function () { |
||||||
return this.table.getCalculateColumnSize(); |
return this.table.getCalculateColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
setHeaderColumnSize: function (columnSize) { |
setHeaderColumnSize: function (columnSize) { |
||||||
return this.table.setHeaderColumnSize(columnSize); |
return this.table.setHeaderColumnSize(columnSize); |
||||||
}, |
}, |
||||||
|
|
||||||
setRegionColumnSize: function (columnSize) { |
setRegionColumnSize: function (columnSize) { |
||||||
return this.table.setRegionColumnSize(columnSize); |
return this.table.setRegionColumnSize(columnSize); |
||||||
}, |
}, |
||||||
|
|
||||||
getRegionColumnSize: function () { |
getRegionColumnSize: function () { |
||||||
return this.table.getRegionColumnSize(); |
return this.table.getRegionColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getCalculateRegionColumnSize: function () { |
getCalculateRegionColumnSize: function () { |
||||||
return this.table.getCalculateRegionColumnSize(); |
return this.table.getCalculateRegionColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getCalculateRegionRowSize: function () { |
getCalculateRegionRowSize: function () { |
||||||
return this.table.getCalculateRegionRowSize(); |
return this.table.getCalculateRegionRowSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getClientRegionColumnSize: function () { |
getClientRegionColumnSize: function () { |
||||||
return this.table.getClientRegionColumnSize(); |
return this.table.getClientRegionColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getScrollRegionColumnSize: function () { |
getScrollRegionColumnSize: function () { |
||||||
return this.table.getScrollRegionColumnSize(); |
return this.table.getScrollRegionColumnSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
getScrollRegionRowSize: function () { |
getScrollRegionRowSize: function () { |
||||||
return this.table.getScrollRegionRowSize(); |
return this.table.getScrollRegionRowSize(); |
||||||
}, |
}, |
||||||
|
|
||||||
hasVerticalScroll: function () { |
hasVerticalScroll: function () { |
||||||
return this.table.hasVerticalScroll(); |
return this.table.hasVerticalScroll(); |
||||||
}, |
}, |
||||||
|
|
||||||
setVerticalScroll: function (scrollTop) { |
setVerticalScroll: function (scrollTop) { |
||||||
return this.table.setVerticalScroll(scrollTop); |
return this.table.setVerticalScroll(scrollTop); |
||||||
}, |
}, |
||||||
|
|
||||||
setLeftHorizontalScroll: function (scrollLeft) { |
setLeftHorizontalScroll: function (scrollLeft) { |
||||||
return this.table.setLeftHorizontalScroll(scrollLeft); |
return this.table.setLeftHorizontalScroll(scrollLeft); |
||||||
}, |
}, |
||||||
|
|
||||||
setRightHorizontalScroll: function (scrollLeft) { |
setRightHorizontalScroll: function (scrollLeft) { |
||||||
return this.table.setRightHorizontalScroll(scrollLeft); |
return this.table.setRightHorizontalScroll(scrollLeft); |
||||||
}, |
}, |
||||||
|
|
||||||
getVerticalScroll: function () { |
getVerticalScroll: function () { |
||||||
return this.table.getVerticalScroll(); |
return this.table.getVerticalScroll(); |
||||||
}, |
}, |
||||||
|
|
||||||
getLeftHorizontalScroll: function () { |
getLeftHorizontalScroll: function () { |
||||||
return this.table.getLeftHorizontalScroll(); |
return this.table.getLeftHorizontalScroll(); |
||||||
}, |
}, |
||||||
|
|
||||||
getRightHorizontalScroll: function () { |
getRightHorizontalScroll: function () { |
||||||
return this.table.getRightHorizontalScroll(); |
return this.table.getRightHorizontalScroll(); |
||||||
}, |
}, |
||||||
|
|
||||||
getColumns: function () { |
getColumns: function () { |
||||||
return this.table.getColumns(); |
return this.table.getColumns(); |
||||||
}, |
}, |
||||||
|
|
||||||
populate: function (items, header) { |
populate: function (items, header) { |
||||||
this.table.populate(items, header); |
if (items) { |
||||||
this._adjustColumns(); |
items = BI.map(items, function (i, items) { |
||||||
} |
return BI.map(items, function (j, item) { |
||||||
}); |
return BI.extend({ |
||||||
BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; |
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); |
BI.shortcut("bi.preview_table", BI.PreviewTable); |
Loading…
Reference in new issue