CommonShowTable.js
1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import React, { Component } from 'react';
import { Table } from 'antd-v4';
// import config from '../../utils/config';
import styles from '../../index.less';
class CommonShowTable extends Component {
constructor(props) {
super(props);
this.state = {
loadColumn: [],
loadData: [],
// ReturnFieldName:props.ReturnFieldName,
currentKey: props.currentKey, /* 选中当前的行 */
};
}
componentWillMount() {
/* 获取表数据 */
this.assignmentWillProps(this.props);
}
componentWillReceiveProps(nextProps) {
this.assignmentWillProps(nextProps);
}
assignmentWillProps = (props) => {
const { name } = props;
const { [`${name}Column`]: headerColumn, [`${name}Data`]: returnData } = props;
const showColumn = [];
if (headerColumn !== undefined) {
headerColumn.forEach((item) => {
showColumn.push({
title: item.showName,
dataIndex: item.sName,
key: item.sName,
});
});
}
this.setState({ loadColumn: headerColumn === undefined ? [] : showColumn, loadData: returnData === undefined ? [] : returnData });
}
handleClick = (record) => {
/* const { sReturnFieldName } = this.props;
const key = record[sReturnFieldName];
console.log('key: ', key); */
this.props.onRowSelect(this.props.name, record);
};
render() {
const { loadColumn, loadData, currentKey } = this.state;
return (
<Table
bordered
columns={loadColumn}
dataSource={loadData}
size="small"
pagination={false}
scroll={{ y: 220 }}
onRow={(record) => {
return { onClick: () => { this.handleClick(record); } };
}}
rowClassName={(record) => {
if (record.key === currentKey) {
return `${styles.clickRow}`;
} else {
return '';
}
}}
/>
);
}
}
export default CommonShowTable;