| | |
| | | save = e => { |
| | | const { record, handleSave } = this.props |
| | | this.form.validateFields((error, values) => { |
| | | handleSave({ ...record, ...values }) |
| | | if (error && error[e.currentTarget.id]) { |
| | | return |
| | | } |
| | | this.toggleEdit() |
| | | handleSave({ ...record, ...values }) |
| | | // handleSave({ ...record, ...values }) |
| | | }) |
| | | } |
| | | |
| | | renderCell = form => { |
| | | this.form = form |
| | | const { children, dataIndex, record, title } = this.props |
| | | // const { children, dataIndex, record, title } = this.props |
| | | const { children, dataIndex, record } = this.props |
| | | const { editing } = this.state |
| | | return editing ? ( |
| | | <Form.Item style={{ margin: 0 }}> |
| | |
| | | rules: [ |
| | | { |
| | | required: true, |
| | | message: `${title} is required.`, |
| | | // message: `${title} is required.`, |
| | | message: 'NOT NULL.', |
| | | }, |
| | | ], |
| | | initialValue: record[dataIndex] |
| | | })(<Input ref={node => (this.input = node)} onPressEnter={this.save} onBlur={this.save} />)} |
| | | })(<Input ref={node => (this.input = node)} autoComplete="off" onPressEnter={this.save} onBlur={this.save} />)} |
| | | </Form.Item> |
| | | ) : ( |
| | | <div |
| | |
| | | class EditTable extends Component { |
| | | constructor(props) { |
| | | super(props) |
| | | this.columns = [ |
| | | let columns = [ |
| | | { |
| | | title: 'ID', |
| | | dataIndex: 'ID', |
| | | width: '40%', |
| | | title: 'Value', |
| | | dataIndex: 'Value', |
| | | width: props.type === 'link' ? '27%' : '40%', |
| | | editable: true |
| | | }, |
| | | { |
| | | title: 'Value', |
| | | dataIndex: 'value', |
| | | width: '40%', |
| | | title: 'Text', |
| | | dataIndex: 'Text', |
| | | width: props.type === 'link' ? '27%' : '40%', |
| | | editable: true |
| | | }, |
| | | { |
| | |
| | | } |
| | | ] |
| | | |
| | | if (props.type === 'link') { |
| | | columns.unshift({ |
| | | title: 'ParentID', |
| | | dataIndex: 'ParentID', |
| | | width: '27%', |
| | | editable: true |
| | | }) |
| | | } |
| | | |
| | | this.state = { |
| | | columns: columns, |
| | | dataSource: props.data, |
| | | count: props.data.length |
| | | count: props.data.length, |
| | | type: props.type |
| | | } |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | handleAdd = () => { |
| | | const { count, dataSource } = this.state |
| | | const { type, count, dataSource } = this.state |
| | | const newData = { |
| | | key: Utils.getuuid(), |
| | | ID: `${count}`, |
| | | value: `${count}` |
| | | Value: `${count}`, |
| | | Text: `${count}` |
| | | } |
| | | if (type === 'link') { |
| | | newData.ParentID = `${count}` |
| | | } |
| | | this.setState({ |
| | | dataSource: [...dataSource, newData], |
| | |
| | | this.setState({ dataSource: newData }) |
| | | } |
| | | |
| | | // UNSAFE_componentWillMount () { |
| | | // if (this.props.data) { |
| | | // this.setState({ |
| | | // dataSource: this.props.data, |
| | | // count: this.props.data.length |
| | | // }) |
| | | // } |
| | | // } |
| | | resetColumn = (type) => { |
| | | let columns = [ |
| | | { |
| | | title: 'Value', |
| | | dataIndex: 'Value', |
| | | width: type === 'link' ? '27%' : '40%', |
| | | editable: true |
| | | }, |
| | | { |
| | | title: 'Text', |
| | | dataIndex: 'Text', |
| | | width: type === 'link' ? '27%' : '40%', |
| | | editable: true |
| | | }, |
| | | { |
| | | title: '操作', |
| | | align: 'center', |
| | | dataIndex: 'operation', |
| | | render: (text, record) => |
| | | this.state.dataSource.length >= 1 ? ( |
| | | <Popconfirm title="Sure to delete?" onConfirm={() => this.handleDelete(record.key)}> |
| | | <span style={{color: '#1890ff', cursor: 'pointer'}}><Icon type="delete" /></span> |
| | | </Popconfirm> |
| | | ) : null, |
| | | } |
| | | ] |
| | | |
| | | if (type === 'link') { |
| | | columns.unshift({ |
| | | title: 'ParentID', |
| | | dataIndex: 'ParentID', |
| | | width: '27%', |
| | | editable: true |
| | | }) |
| | | } |
| | | |
| | | this.setState({ |
| | | columns: columns, |
| | | type: type |
| | | }) |
| | | } |
| | | |
| | | UNSAFE_componentWillReceiveProps (nextProps) { |
| | | if (this.props.type !== nextProps.type) { |
| | | this.resetColumn(nextProps.type) |
| | | } |
| | | } |
| | | |
| | | render() { |
| | | const { dataSource } = this.state |
| | |
| | | cell: EditableCell |
| | | } |
| | | } |
| | | const columns = this.columns.map(col => { |
| | | const columns = this.state.columns.map(col => { |
| | | if (!col.editable) { |
| | | return col |
| | | } |