From 3d4a4002f75c7ac0f64ad440974b88a8fcf2691b Mon Sep 17 00:00:00 2001 From: huyueb <1062887235@qq.com> Date: Thu, 28 Sep 2017 14:29:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E5=90=88=E8=AE=A1?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/lib/sum.js | 24 +++++++----------------- 1 file changed, 7 insertions(+), 17 deletions(-) diff --git a/src/lib/sum.js b/src/lib/sum.js index 7ddaf19..86fbe78 100644 --- a/src/lib/sum.js +++ b/src/lib/sum.js @@ -1,28 +1,25 @@ import React from "react"; -import Table from "../../src"; //创建新列存放 “合计” 字段 -let columns2 = {}; -columns2 = { +let columns2 = { title: "合计", key: "showSum", dataIndex: "showSum" }; -var Sum = Table => { - class SumTable extends React.Component { +let Sum = Table => { + return class SumTable extends React.Component { //无状态 constructor(props) { super(props); } - currentTitle = () => { return
{this.props.title}
; }; - //合计数字列,并将计算所得数据存储到一个obj对象中 currentFooter = () => { let data_2 = this.props.data; + let columns_sum = this.props.columns; //用一个对象存储合计数据,这里合计对象的属性对应每列字段 let obj = {}; if (Array.isArray(data_2)) { @@ -38,16 +35,11 @@ var Sum = Table => { } } } - //加key obj.key = "sumData"; - //设置新建列的名称 obj.showSum = "合计"; obj = [obj]; - //添加合计行 - let columns_sum = this.props.columns; - //针对多选除去多选框,即第一列,换为新建的列 - columns_sum[0] = Object.assign({},columns_sum[0],columns2); - console.log(columns_sum); + //将设置的和用户传入的合并属性 + columns_sum[0] = Object.assign({}, columns_sum[0], columns2); //除去列为特殊渲染的,避免像a标签这种html代码写入到合计中 columns_sum = columns_sum.map((item, index) => { if (typeof item.render == "function") { @@ -55,7 +47,6 @@ var Sum = Table => { } return item; }); - return ( { /> ); } - } - return SumTable; + }; }; export default Sum;