import { Table, Input, Icon, Button, Popconfirm, Popover, Tooltip } from 'antd';
import "./index.less"
export class EditableCell extends React.Component {
state = {
value: this.props.value,
record: this.props.record
}
handleChange = (e) => {
const value = e.target.value;
this.setState({ value });
this.props.onChange(value);
}
render() {
const { value } = this.state;
const { editable } = this.props;
return (
);
}
}
export default class EditableTable extends React.Component {
constructor(props) {
super(props);
const { columns } = this.props;
this.columns = columns;
this.columns.map(item => {
if (item.editable) {
item.render = (text, record) => (
)
}
if(item.popover) {
item.render = (text, record) => (
{
this.onItemDelete(record)
}} />
}>
{text}
)
}
if (item.children) {
item.children.map(child => {
if (child.editable) {
child.render = (text, record) => (
)
}
}
)
}
})
}
onCellChange = (indexNum, dataIndex) => {
return (value) => {
const dataSource = [...this.props.dataSource];
const target = dataSource.find(item => item.indexNum === indexNum);
if (target) {
target[dataIndex] = value;
this.props.onDataSourceChange(dataSource)
}
};
}
onItemDelete = (record) => {
let dataSource = [...this.props.dataSource];
dataSource = dataSource.filter(item => item.indexNum != record.indexNum)
dataSource.map((item, index) => {
item.indexNum = index + 1
})
this.props.onDataSourceChange(dataSource)
}
render() {
const columns = this.columns;
const { editable } = this.props;
return (
{
editable &&
{
this.props.addItem()
}} />
}
);
}
}