| | |
| | | }) |
| | | } |
| | | |
| | | handleAdd = (e) => { |
| | | e.stopPropagation() |
| | | const { dataSource, selectedRowKeys } = this.state |
| | | const item = { |
| | | uuid: Utils.getuuid(), |
| | | key: '', |
| | | value: '', |
| | | description: '', |
| | | selected: true |
| | | } |
| | | |
| | | let _data = [...dataSource, item] |
| | | |
| | | this.setState({ |
| | | dataSource: _data, |
| | | selectedRowKeys: [...selectedRowKeys, item.uuid] |
| | | }, () => { |
| | | this.props.onChange(_data) |
| | | }) |
| | | } |
| | | |
| | | handleSave = row => { |
| | | const newData = this.state.dataSource.map(item => { |
| | | let newData = this.state.dataSource.map(item => { |
| | | if (row.uuid === item.uuid) return row |
| | | return item |
| | | }) |
| | | |
| | | this.setState({ dataSource: newData }, () => { |
| | | let selectedRowKeys = this.state.selectedRowKeys |
| | | |
| | | let last = newData[newData.length - 1] |
| | | if (last.key || last.value || last.description) { |
| | | const item = { |
| | | uuid: Utils.getuuid(), |
| | | key: '', |
| | | value: '', |
| | | description: '', |
| | | selected: true |
| | | } |
| | | |
| | | newData = [...newData, item] |
| | | selectedRowKeys = [...selectedRowKeys, item.uuid] |
| | | } |
| | | |
| | | this.setState({ dataSource: newData, selectedRowKeys }, () => { |
| | | this.props.onChange(newData) |
| | | }) |
| | | } |
| | |
| | | }) |
| | | return ( |
| | | <div className="params-edit-table"> |
| | | <Icon className="add-row" type="plus" onClick={this.handleAdd} /> |
| | | <Table |
| | | rowKey="uuid" |
| | | components={components} |