-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditableCell.jsx
More file actions
76 lines (71 loc) · 1.49 KB
/
EditableCell.jsx
File metadata and controls
76 lines (71 loc) · 1.49 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
76
import React from "react";
import { Input, Select, Form } from "antd";
/**
* EditableCell
* @param {props} param
* @returns {React.Component}
*/
const EditableCell = ({
wrapForm,
rowData,
dataIndex,
title,
isRequired,
editing,
children,
...restProps
}) => {
// 渲染编辑模式时的Node
const renderInputNode = () => {
switch (dataIndex) {
case "name": {
return <Input placeholder="请输入" />;
}
case "value": {
return (
<Select mode="multiple" placeholder="请选择">
<Select.Option value="value1">选项1</Select.Option>
</Select>
);
}
default: {
return <Input placeholder="请输入" />;
}
}
};
// 渲染只读模式时的Node
const renderChildNode = () => {
switch (dataIndex) {
case "other": {
return rowData[dataIndex];
}
default: {
return children;
}
}
};
const newRestProps = { ...restProps };
if (newRestProps.wrapForm) {
delete newRestProps.wrapForm;
}
return (
<td
{...restProps}
className={`${restProps.className || ""} editable-cell${
dataIndex ? ` ${dataIndex}-cell` : ""
}`}
>
{editing ? (
<Form.Item
name={dataIndex}
className={`table-cell-form-item ${dataIndex}-field`}
>
{renderInputNode()}
</Form.Item>
) : (
renderChildNode()
)}
</td>
);
};
export default EditableCell;