| | |
| | | }) |
| | | } |
| | | |
| | | changeDatatype = (column) => { |
| | | const { columns, dataSource } = this.state |
| | | let value = column.datatype !== 'number' ? 'number' : 'string' |
| | | let _data = dataSource.map(item => { |
| | | let val = item[column.dataIndex] |
| | | if (value === 'number') { |
| | | val = parseFloat(val) |
| | | if (isNaN(val)) { |
| | | val = 0 |
| | | } |
| | | } else { |
| | | val = '' + val |
| | | } |
| | | // changeDatatype = (column) => { |
| | | // const { columns, dataSource } = this.state |
| | | // let value = column.datatype !== 'number' ? 'number' : 'string' |
| | | // let _data = dataSource.map(item => { |
| | | // let val = item[column.dataIndex] |
| | | // if (value === 'number') { |
| | | // val = parseFloat(val) |
| | | // if (isNaN(val)) { |
| | | // val = 0 |
| | | // } |
| | | // } else { |
| | | // val = '' + val |
| | | // } |
| | | |
| | | item[column.dataIndex] = val |
| | | // item[column.dataIndex] = val |
| | | |
| | | return item |
| | | }) |
| | | // return item |
| | | // }) |
| | | |
| | | this.setState({ |
| | | dataSource: _data, |
| | | columns: columns.map(col => { |
| | | if (col.dataIndex === column.dataIndex) { |
| | | col.datatype = value |
| | | } |
| | | // this.setState({ |
| | | // dataSource: _data, |
| | | // columns: columns.map(col => { |
| | | // if (col.dataIndex === column.dataIndex) { |
| | | // col.datatype = value |
| | | // } |
| | | |
| | | if (col.dataIndex !== 'operation') { |
| | | col.title = <div> |
| | | {col.$title} |
| | | <Popconfirm |
| | | title={`确定切换为${col.datatype === 'number' ? '文本' : '数值'}吗?`} |
| | | overlayClassName="popover-confirm" |
| | | onConfirm={() => this.changeDatatype(col) |
| | | }> |
| | | <SwapOutlined style={{ color: col.datatype === 'number' ? '#1890ff' : ''}} /> |
| | | </Popconfirm> |
| | | </div> |
| | | } |
| | | // if (col.dataIndex !== 'operation') { |
| | | // col.title = <div> |
| | | // {col.$title} |
| | | // {/* <Popconfirm |
| | | // title={`确定切换为${col.datatype === 'number' ? '文本' : '数值'}吗?`} |
| | | // overlayClassName="popover-confirm" |
| | | // onConfirm={() => this.changeDatatype(col) |
| | | // }> |
| | | // <SwapOutlined style={{ color: col.datatype === 'number' ? '#1890ff' : ''}} /> |
| | | // </Popconfirm> */} |
| | | // </div> |
| | | // } |
| | | |
| | | return col |
| | | }) |
| | | }, () => { |
| | | this.props.onChange(_data) |
| | | }) |
| | | } |
| | | // return col |
| | | // }) |
| | | // }, () => { |
| | | // this.props.onChange(_data) |
| | | // }) |
| | | // } |
| | | |
| | | handleUpDown = (record, direction) => { |
| | | const { dataSource } = this.state |
| | |
| | | if (col.dataIndex !== 'operation') { |
| | | col.title = <div> |
| | | {col.$title} |
| | | <Popconfirm |
| | | {/* <Popconfirm |
| | | title={`确定切换为${col.datatype === 'number' ? '文本' : '数值'}吗?`} |
| | | overlayClassName="popover-confirm" |
| | | onConfirm={() => this.changeDatatype(col) |
| | | }> |
| | | <SwapOutlined style={{ color: col.datatype === 'number' ? '#1890ff' : ''}} /> |
| | | </Popconfirm> |
| | | </Popconfirm> */} |
| | | </div> |
| | | } |
| | | return col |