fix: 优化合计组件语法

This commit is contained in:
huyueb 2017-09-28 14:29:18 +08:00
parent e26f3b5765
commit 3d4a4002f7
1 changed files with 7 additions and 17 deletions

View File

@ -1,28 +1,25 @@
import React from "react"; import React from "react";
import Table from "../../src";
//创建新列存放 “合计” 字段 //创建新列存放 “合计” 字段
let columns2 = {}; let columns2 = {
columns2 = {
title: "合计", title: "合计",
key: "showSum", key: "showSum",
dataIndex: "showSum" dataIndex: "showSum"
}; };
var Sum = Table => { let Sum = Table => {
class SumTable extends React.Component { return class SumTable extends React.Component {
//无状态 //无状态
constructor(props) { constructor(props) {
super(props); super(props);
} }
currentTitle = () => { currentTitle = () => {
return <div>{this.props.title}</div>; return <div>{this.props.title}</div>;
}; };
//合计数字列,并将计算所得数据存储到一个obj对象中 //合计数字列,并将计算所得数据存储到一个obj对象中
currentFooter = () => { currentFooter = () => {
let data_2 = this.props.data; let data_2 = this.props.data;
let columns_sum = this.props.columns;
//用一个对象存储合计数据,这里合计对象的属性对应每列字段 //用一个对象存储合计数据,这里合计对象的属性对应每列字段
let obj = {}; let obj = {};
if (Array.isArray(data_2)) { if (Array.isArray(data_2)) {
@ -38,16 +35,11 @@ var Sum = Table => {
} }
} }
} }
//加key
obj.key = "sumData"; obj.key = "sumData";
//设置新建列的名称
obj.showSum = "合计"; obj.showSum = "合计";
obj = [obj]; obj = [obj];
//添加合计行 //将设置的和用户传入的合并属性
let columns_sum = this.props.columns; columns_sum[0] = Object.assign({}, columns_sum[0], columns2);
//针对多选除去多选框,即第一列,换为新建的列
columns_sum[0] = Object.assign({},columns_sum[0],columns2);
console.log(columns_sum);
//除去列为特殊渲染的避免像a标签这种html代码写入到合计中 //除去列为特殊渲染的避免像a标签这种html代码写入到合计中
columns_sum = columns_sum.map((item, index) => { columns_sum = columns_sum.map((item, index) => {
if (typeof item.render == "function") { if (typeof item.render == "function") {
@ -55,7 +47,6 @@ var Sum = Table => {
} }
return item; return item;
}); });
return ( return (
<Table <Table
showHeader={false} showHeader={false}
@ -76,8 +67,7 @@ var Sum = Table => {
/> />
); );
} }
} };
return SumTable;
}; };
export default Sum; export default Sum;