Antd新增、修改的可编辑表格

import React, { PureComponent } from 'react';
import { Form, Table, InputNumber } from 'antd';

export default class DTable extends PureComponent {
  changeInput = (record, value) => {
    const { data } = this.props;
    data[record.field] = value;
  }
  getRequired = () => {
    const { data } = this.props;
    const fields = initData.map(v => v.field);
    for (const item of fields) {
      if (data[item]) return true;
    }
    return false;
  }
  render() {
    const { form: { getFieldDecorator }, data, isCheck } = this.props;
    const isRequired = this.getRequired();
    const columns = [
      {
        title: '指标名称',
        dataIndex: 'indexName',
        width: '60%',
      },
      {
        title: '指标值',
        dataIndex: 'indexValue',
        width: '40%',
        render(text, record) {
          if (isCheck) return data[record.field];
          return (
            <Form.Item
              wrapperCol={{ span: 24 }}
              style={{ marginBottom: 0 }}
            >
              {getFieldDecorator('indexValue' + data.professionalCategory + record.key, {
                rules: [{ required: isRequired, message: ' ' }],
                initialValue: data[record.field],
              })(
                <InputNumber
                  style={{ width: '100%' }}
                  placeholder={isRequired ? '此项必填' : '此项非必填'}
                  min={0}
                  onChange={(value) => { data[record.field] = value; }}
                />
              )}
            </Form.Item>
          );
        },
      },
    ];
    return (
      <Table
        loading={this.props.loading}
        dataSource={initData}
        columns={columns}
        bordered
        pagination={false}
        rowKey="key"
        scroll={{ y: '500px' }}
      />
    );
  }
}
//写死数据格式
const initData = [{
  key: '1',
  indexName: '类型不符合要求的标本数',
  indexValue: '',
  field: 'typeIncorredSpecimen',
},.....

 

评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值