2018-05-11 11:30:56 +08:00
|
|
|
|
/**
|
|
|
|
|
*
|
2018-09-26 16:36:49 +08:00
|
|
|
|
* @title 多列排序、全选功能、合计
|
|
|
|
|
* @description 多列排序、全选功能、合计(通过使用的封装好的功能方法实现复杂功能,简单易用!)新增回调函数(sorterClick)
|
2018-05-11 11:30:56 +08:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React, { Component } from "react";
|
|
|
|
|
import Table from "../../src";
|
|
|
|
|
import Checkbox from "bee-checkbox";
|
|
|
|
|
import Button from "bee-button";
|
2018-05-22 19:38:15 +08:00
|
|
|
|
import Icon from "bee-icon";
|
2018-05-11 11:30:56 +08:00
|
|
|
|
import multiSelect from "../../src/lib/multiSelect.js";
|
|
|
|
|
import sort from "../../src/lib/sort.js";
|
|
|
|
|
import sum from "../../src/lib/sum.js";
|
|
|
|
|
|
|
|
|
|
const columns13 = [
|
|
|
|
|
{
|
|
|
|
|
title: "名字",
|
|
|
|
|
dataIndex: "a",
|
|
|
|
|
key: "a",
|
2018-09-26 16:36:49 +08:00
|
|
|
|
className:'dfasd',
|
2018-05-11 11:30:56 +08:00
|
|
|
|
width: 200
|
|
|
|
|
},
|
|
|
|
|
{
|
2018-08-02 13:12:13 +08:00
|
|
|
|
title: "功力指数",
|
2018-05-11 11:30:56 +08:00
|
|
|
|
dataIndex: "b",
|
|
|
|
|
key: "b",
|
2018-08-02 13:12:13 +08:00
|
|
|
|
width: 200,
|
|
|
|
|
sumCol: true,
|
|
|
|
|
sorter: (a, b) => a.c - b.c,
|
|
|
|
|
sorterClick:(data,type)=>{//排序的回调函数
|
|
|
|
|
//type value is up or down
|
|
|
|
|
console.log("data",data);
|
|
|
|
|
}
|
2018-05-11 11:30:56 +08:00
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
title: "年龄",
|
|
|
|
|
dataIndex: "c",
|
|
|
|
|
key: "c",
|
|
|
|
|
width: 200,
|
|
|
|
|
sumCol: true,
|
2018-07-16 16:19:51 +08:00
|
|
|
|
sorter: (a, b) => a.c - b.c,
|
2018-07-17 16:27:23 +08:00
|
|
|
|
sorterClick:(data,type)=>{//排序的回调函数
|
|
|
|
|
//type value is up or down
|
2018-07-16 16:19:51 +08:00
|
|
|
|
console.log("data",data);
|
|
|
|
|
}
|
2018-05-11 11:30:56 +08:00
|
|
|
|
},
|
2018-09-26 16:36:49 +08:00
|
|
|
|
{
|
|
|
|
|
title: "成绩",
|
|
|
|
|
dataIndex: "e",
|
|
|
|
|
key: "e",
|
|
|
|
|
width: 200,
|
|
|
|
|
sumCol: true,
|
|
|
|
|
sorter: (a, b) => a.c - b.c,
|
|
|
|
|
},
|
2018-05-11 11:30:56 +08:00
|
|
|
|
{
|
|
|
|
|
title: "武功级别",
|
|
|
|
|
dataIndex: "d",
|
|
|
|
|
key: "d",
|
2018-12-19 15:45:25 +08:00
|
|
|
|
fixed:'right',
|
2018-05-11 11:30:56 +08:00
|
|
|
|
width: 200
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const data13 = [
|
2018-12-19 15:45:25 +08:00
|
|
|
|
{ a: "令狐冲", b: 43, c: 41, d: "大侠",e:90.52, key: "1" },
|
|
|
|
|
|
2018-05-11 11:30:56 +08:00
|
|
|
|
];
|
2018-09-26 16:36:49 +08:00
|
|
|
|
|
2018-05-11 11:30:56 +08:00
|
|
|
|
//拼接成复杂功能的table组件不能在render中定义,需要像此例子声明在组件的外侧,不然操作state会导致功能出现异常
|
2018-05-22 19:38:15 +08:00
|
|
|
|
let ComplexTable = multiSelect(sum(sort(Table, Icon)), Checkbox);
|
2018-05-11 11:30:56 +08:00
|
|
|
|
|
|
|
|
|
class Demo13 extends Component {
|
|
|
|
|
constructor(props) {
|
|
|
|
|
super(props);
|
|
|
|
|
this.state = {
|
|
|
|
|
data13: data13,
|
|
|
|
|
selectedRow: this.selectedRow,
|
|
|
|
|
selectDisabled: this.selectDisabled
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
getSelectedDataFunc = data => {
|
2018-07-06 14:33:29 +08:00
|
|
|
|
console.log(data);
|
2018-05-11 11:30:56 +08:00
|
|
|
|
};
|
|
|
|
|
selectDisabled = (record, index) => {
|
|
|
|
|
// console.log(record);
|
|
|
|
|
if (index === 1) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
selectedRow = (record, index) => {
|
|
|
|
|
// console.log(record);
|
|
|
|
|
if (index === 0) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
};
|
|
|
|
|
onClick = () => {
|
|
|
|
|
this.setState({
|
|
|
|
|
selectedRow: function() {}
|
|
|
|
|
});
|
|
|
|
|
};
|
2018-09-07 16:06:35 +08:00
|
|
|
|
|
2018-05-11 11:30:56 +08:00
|
|
|
|
render() {
|
|
|
|
|
let multiObj = {
|
|
|
|
|
type: "checkbox"
|
|
|
|
|
};
|
2018-09-26 16:36:49 +08:00
|
|
|
|
let sortObj = {
|
2018-09-25 14:31:20 +08:00
|
|
|
|
mode:'multiple'
|
|
|
|
|
}
|
2018-09-26 16:36:49 +08:00
|
|
|
|
|
2018-05-11 11:30:56 +08:00
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Button className="editable-add-btn" onClick={this.onClick}>
|
|
|
|
|
change selectedRow
|
|
|
|
|
</Button>
|
|
|
|
|
<ComplexTable
|
|
|
|
|
selectDisabled={this.state.selectDisabled}
|
|
|
|
|
selectedRow={this.state.selectedRow}
|
|
|
|
|
columns={columns13}
|
|
|
|
|
data={this.state.data13}
|
|
|
|
|
multiSelect={multiObj}
|
2018-09-26 16:36:49 +08:00
|
|
|
|
sort={sortObj}
|
2018-12-19 15:45:25 +08:00
|
|
|
|
scroll={{x:'100%',y:100}}
|
2018-05-11 11:30:56 +08:00
|
|
|
|
getSelectedDataFunc={this.getSelectedDataFunc}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
export default Demo13;
|