feat: 提供column.sumThousandth属性,用于设置合计行是否开启千分位功能

This commit is contained in:
Jarvan 2020-10-14 15:25:17 +08:00
parent 90f2de3bbb
commit 0a8f8c362b
16 changed files with 4996 additions and 6256 deletions

File diff suppressed because it is too large Load Diff

View File

@ -177,6 +177,8 @@
position: relative;
line-height: 1.33;
overflow: hidden; }
.u-table.copy .u-table-thead th {
user-select: unset; }
.u-table-body {
position: relative; }
.u-table-body .u-table-row-expand-columns-in-body .expand-icon-con {

View File

@ -639,7 +639,8 @@ var Table = function (_Component) {
onDropBorder = _props2.onDropBorder,
onDraggingBorder = _props2.onDraggingBorder,
bodyDisplayInRow = _props2.bodyDisplayInRow,
headerEventNoStop = _props2.headerEventNoStop;
headerEventNoStop = _props2.headerEventNoStop,
onCopy = _props2.onCopy;
this.columnsChildrenList = []; //复杂表头拖拽重新render表头前将其置空
var rows = this.getHeaderRows(columns);
@ -688,7 +689,8 @@ var Table = function (_Component) {
leftFixedWidth: leftFixedWidth,
rightFixedWidth: rightFixedWidth,
bodyDisplayInRow: bodyDisplayInRow,
eventNoStop: headerEventNoStop
eventNoStop: headerEventNoStop,
onCopy: onCopy
})) : null;
};
@ -1640,6 +1642,9 @@ var Table = function (_Component) {
if (props.bordered) {
className += ' ' + clsPrefix + '-bordered';
}
if (props.onCopy) {
className += ' copy';
}
className += ' ' + clsPrefix + '-scroll-position-' + this.state.scrollPosition;
//如果传入height说明是固定高度
//内容过多折行显示时height 属性会失效,为了避免产生错行

View File

@ -515,7 +515,9 @@ var TableHeader = function (_Component) {
return _react2["default"].createElement(
"th",
_extends({}, da, keyTemp, { className: thClassName, "data-th-fixed": da.fixed, "data-line-key": da.key,
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable" }),
"data-line-index": columIndex, "data-th-width": da.width, "data-type": "draggable", onCopy: function onCopy(event) {
_this7.onCopy(da, columIndex, event);
} }),
da.children,
// && columIndex != _rowLeng
@ -536,7 +538,7 @@ var TableHeader = function (_Component) {
da.onClick ? thDefaultObj.onClick = function (e) {
da.onClick(da, e);
} : "";
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width } }));
return _react2["default"].createElement("th", _extends({}, thDefaultObj, keyTemp, { "data-th-fixed": da.fixed, style: { maxWidth: da.width }, onCopy: _this7.onCopy }));
}
})
);
@ -1051,6 +1053,12 @@ var _initialiseProps = function _initialiseProps() {
return _react2["default"].createElement("div", null);
}
};
this.onCopy = function (data, index, event) {
if (_this8.props.onCopy) {
_this8.props.onCopy(_extends(data, { col: index }), event);
}
};
};
TableHeader.propTypes = propTypes;

View File

@ -96,15 +96,17 @@ function bigData(Table) {
_this.treeType = isTreeType;
//fix: 滚动加载场景中,数据动态改变下占位计算错误的问题(26 Jun)
if (newData.toString() !== props.data.toString()) {
_this.cachedRowHeight = []; //缓存每行的高度
_this.cachedRowParentIndex = [];
_this.computeCachedRowParentIndex(newData);
// fix切换数据源startIndex、endIndex错误
if (_this.scrollTop <= 0) {
// 增加scrollTop 判断ncc场景下滚动条不在最上层 会出现空白因为重置了currentIndex没有重置滚动条
_this.currentIndex = 0;
_this.startIndex = _this.currentIndex; //数据开始位置
_this.endIndex = _this.currentIndex + _this.loadCount;
}
}
_this.treeData = [];
_this.flatTreeData = [];
if (newData.length > 0) {

View File

@ -94,6 +94,9 @@ function sum(Table) {
}
});
var _sum = (0, _utils.DicimalFormater)(count, precision);
if (column.sumThousandth) {
_sum = _this.toThousands(_sum);
}
sumdata[column.dataIndex] = _sum;
if (column.sumRender && typeof column.sumRender == 'function') {
sumdata[column.dataIndex] = column.sumRender(_sum);
@ -118,6 +121,22 @@ function sum(Table) {
*/
SumTable.prototype.toThousands = function toThousands(num) {
var result = '',
counter = 0;
num = (num || 0).toString();
var numArr = num.split('.');
num = numArr[0];
for (var i = num.length - 1; i >= 0; i--) {
counter++;
result = num.charAt(i) + result;
if (!(counter % 3) && i != 0) {
result = ',' + result;
}
}
return numArr.length === 1 ? result : result + '.' + numArr[1];
};
SumTable.prototype.render = function render() {
return _react2["default"].createElement(Table, _extends({}, this.props, {
columns: this.props.columns,

View File

@ -57,14 +57,16 @@ const columns = [
dataIndex: "total",
key: "total",
width: 100,
sumCol: true
sumCol: true,
sumThousandth: true
},
{
title: "金额",
dataIndex: "money",
key: "money",
width: 100,
sumCol: true
sumCol: true,
sumThousandth: true
}
];
@ -80,7 +82,7 @@ function getData(){
contact: "Tom",
warehouse: "普通仓",
total: i + Math.floor(Math.random()*10),
money: 20 * Math.floor(Math.random()*10)
money: 2000 * Math.floor(Math.random()*10)
});
_sum += data[i].total;
_sum += data[i].money;

File diff suppressed because one or more lines are too long

2
dist/demo.css.map vendored

File diff suppressed because one or more lines are too long

7791
dist/demo.js vendored

File diff suppressed because one or more lines are too long

2
dist/demo.js.map vendored

File diff suppressed because one or more lines are too long

View File

@ -37,7 +37,18 @@ export default function sum(Table,precision=2) {
return type;
}
toThousands(num) {
let result = '', counter = 0;
num = (num || 0).toString();
const numArr = num.split('.')
num = numArr[0]
for (var i = num.length - 1; i >= 0; i--) {
counter++;
result = num.charAt(i) + result;
if (!(counter % 3) && i != 0) { result = ',' + result; }
}
return numArr.length === 1 ? result : result +'.' +numArr[1];
}
addSumData=()=>{
let {data=[],columns=[]} = this.props;
@ -65,6 +76,9 @@ export default function sum(Table,precision=2) {
})
let sum = DicimalFormater(count,precision);
if(column.sumThousandth) {
sum = this.toThousands(sum)
}
sumdata[column.dataIndex] = sum;
if(column.sumRender&&typeof column.sumRender =='function'){
sumdata[column.dataIndex] = column.sumRender(sum)