From e2d6be5a2216e3dfd9c917adba196941f0454a18 Mon Sep 17 00:00:00 2001 From: huyueb <1062887235@qq.com> Date: Sun, 24 Dec 2017 21:39:45 +0800 Subject: [PATCH] =?UTF-8?q?fix(sum.js):=20=E4=BF=AE=E5=A4=8D=E5=90=88?= =?UTF-8?q?=E8=AE=A1=E5=8A=9F=E8=83=BD=E4=BC=9A=E5=BF=BD=E7=95=A5=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E5=8F=82=E6=95=B0=EF=BC=8C=E5=B9=B6=E5=AF=BC=E8=87=B4?= =?UTF-8?q?render=E4=B8=8D=E7=94=9F=E6=95=88=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/sum.js | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/lib/sum.js b/src/lib/sum.js index 7d34ab2..8ca8227 100644 --- a/src/lib/sum.js +++ b/src/lib/sum.js @@ -1,5 +1,4 @@ import React from "react"; -// import clonedeep from "lodash.clonedeep"; //创建新列存放 “合计” 字段 let columns2 = { @@ -8,7 +7,7 @@ let columns2 = { dataIndex: "showSum" }; -export default function sum(Table){ +export default function sum(Table) { return class SumTable extends React.Component { //无状态 constructor(props) { @@ -30,8 +29,11 @@ export default function sum(Table){ obj[sumCol_index] = 0; if (Array.isArray(data_2)) { for (let i = 0; i < data_2.length; i++) { - if (typeof data_2[i][sumCol_index] == "number") { - obj[sumCol_index] += data_2[i][sumCol_index]; + if ( + typeof data_2[i][sumCol_index] == "number" || + !isNaN(data_2[i][sumCol_index]) + ) { + obj[sumCol_index] -= -data_2[i][sumCol_index]; } else { obj[sumCol_index] = ""; } @@ -41,14 +43,10 @@ export default function sum(Table){ obj.showSum = "合计"; obj = [obj]; //将设置的和用户传入的合并属性 - // if (columns_sum[0].dataIndex === "checkbox") { - // columns_sum[1] = Object.assign({}, columns_sum[1], columns2); - // } else { columns_sum[0] = Object.assign({}, columns_sum[0], columns2); - // } //除去列为特殊渲染的,避免像a标签这种html代码写入到合计中 columns_sum.map((item, index) => { - if (typeof item.render == "function") { + if (typeof item.render == "function" && !item.sumCol) { item.render = ""; } return item; @@ -58,6 +56,7 @@ export default function sum(Table){ render() { return (