feat(合并标题后的合计,且支持多字段统计): 合并标题后的合计,且支持多字段统计

合并标题后的合计,且支持多字段统计

BREAKING CHANGE: 合并标题后的合计,且支持多字段统计
This commit is contained in:
jonyshi 2018-04-18 16:10:02 +08:00
parent 11defcc10d
commit 64d4059316
2 changed files with 99 additions and 2 deletions

View File

@ -37,6 +37,7 @@ function sum(Table) {
function SumTable(props) {
_classCallCheck(this, SumTable);
//array , tree
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props));
_this.currentFooter = function () {
@ -76,17 +77,113 @@ function sum(Table) {
return _react2["default"].createElement(Table, _extends({}, _this.props, { loading: false, footerScroll: true, showHeader: false, columns: columns_sum, data: obj }));
};
_this.currentTreeFooter = function () {
var _this$props = _this.props,
columns = _this$props.columns,
data = _this$props.data;
var _columns = [];
_this.getNodeItem(columns, _columns);
var _countObj = {};
var _iteratorNormalCompletion = true;
var _didIteratorError = false;
var _iteratorError = undefined;
try {
var _loop = function _loop() {
var column = _step.value;
if (typeof column.render == "function" && !column.sumCol) {
column.render = "";
}
if (column.sumCol) {
var count = 0;
data.forEach(function (da, i) {
var _num = da[column.key];
count += _num;
});
_countObj[column.key] = count;
}
};
for (var _iterator = _columns[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
_loop();
}
} catch (err) {
_didIteratorError = true;
_iteratorError = err;
} finally {
try {
if (!_iteratorNormalCompletion && _iterator["return"]) {
_iterator["return"]();
}
} finally {
if (_didIteratorError) {
throw _iteratorError;
}
}
}
var _sumArray = [_extends({ key: "sumData", showSum: "合计" }, _countObj)];
columns[0] = _extends({}, columns[0], columns2);
return _react2["default"].createElement(Table, _extends({}, _this.props, { bordered: false, loading: false, footerScroll: true, showHeader: false, columns: columns, data: _sumArray }));
};
_this.getNodeItem = function (array, newArray) {
array.forEach(function (da, i) {
if (da.children) {
_this.getNodeItem(da.children, newArray);
} else {
newArray.push(da);
}
});
};
_this.getTableType = function () {
var columns = _this.props.columns;
var type = "array";
columns.find(function (da, i) {
if (da.children) {
type = "tree";
return type;
}
});
return type;
};
_this.setFooterRender = function () {
var columns = _this.props.columns;
if (!Array.isArray(columns)) {
console.log("data type is error !");return;
}
var type = _this.getTableType();
if (type == "tree") {
return _this.currentTreeFooter();
} else {
return _this.currentFooter();
}
};
_this.tableType = "array";
return _this;
}
//合计数字列,并将计算所得数据存储到一个obj对象中
/**
* 获取当前的表格类型
*
*/
SumTable.prototype.render = function render() {
return _react2["default"].createElement(Table, _extends({}, this.props, {
footerScroll: true,
columns: this.props.columns,
data: this.props.data,
footer: this.currentFooter
footer: this.setFooterRender
}));
};

View File

@ -1,6 +1,6 @@
{
"name": "bee-table",
"version": "1.1.0",
"version": "1.1.1",
"description": "Table ui component for react",
"keywords": [
"react",