Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [BUG]editorFormRef.current?.setRowData方法不生效 #11051

Closed
Statfine opened this issue Nov 21, 2023 · 2 comments
Closed

🐛 [BUG]editorFormRef.current?.setRowData方法不生效 #11051

Statfine opened this issue Nov 21, 2023 · 2 comments

Comments

@Statfine
Copy link

🐛 bug 描述

EditableProTable表格中 当我修改“车型”下拉框的时候进行“单价”输入框的修改不生效

📷 复现步骤 | Recurrence steps

import { EditableFormInstance, EditableProTable, ProColumns } from '@ant-design/pro-components';
import { memo, useImperativeHandle, useRef, useState } from 'react';

type VehicleModelProps = {
  cRef?: any;
};

type DataSourceType = {
  id: React.Key;
  children?: DataSourceType[];
  type?: string;
  count?: number;
  price?: number;
  amount?: number;
};

const defaultData: DataSourceType[] = new Array(1).fill(1).map((_, index) => {
  return {
    id: (Date.now() + index).toString(),
    type: '1',
    count: 1,
    price: 1,
    amount: 1,
  };
});

const VehicleModel: React.FC<VehicleModelProps> = ({ cRef }) => {
  const editableFormRef = useRef<EditableFormInstance>();

  const [editableKeys, setEditableRowKeys] = useState<React.Key[]>(() =>
    defaultData.map((item) => item.id),
  );
  const [dataSource, setDataSource] = useState<readonly DataSourceType[]>(() => []);

  useImperativeHandle(cRef, () => ({}), []);

  const columns: ProColumns<DataSourceType>[] = [
    {
      title: '车型',
      dataIndex: 'type',
      width: 200,
      valueType: 'select',
      valueEnum: {
        '1': {
          text: '车型1',
        },
        '2': {
          text: '车型2',
        },
      },
      fieldProps: (_, { rowIndex }) => {
        return {
          onSelect: () => {
            editableFormRef.current?.setRowData?.(rowIndex, { price: 10 });
          },
        };
      },
    },
    {
      title: '数量',
      dataIndex: 'count',
      width: 100,
      valueType: 'digit',
      fieldProps: {
        min: 1,
        precision: 0,
      },
    },
    {
      title: '单价',
      dataIndex: 'price',
      width: 100,
      valueType: 'digit',
      fieldProps: {
        min: 0,
        precision: 2,
      },
    },
    {
      title: '总价',
      readonly: true,
      dataIndex: 'amount',
      width: 120,
    },
    {
      title: '操作',
      valueType: 'option',
      width: 60,
      render: () => {
        return null;
      },
    },
  ];

  console.log('dataSource', dataSource);
  return (
    <EditableProTable<DataSourceType>
      editableFormRef={editableFormRef}
      columns={columns}
      rowKey="id"
      scroll={{
        x: 630,
      }}
      value={dataSource}
      onChange={setDataSource}
      recordCreatorProps={{
        newRecordType: 'dataSource',
        record: () => ({
          id: Date.now(),
        }),
      }}
      editable={{
        type: 'multiple',
        editableKeys,
        actionRender: (row, config, defaultDoms) => {
          return [defaultDoms.delete];
        },
        onValuesChange: (record, recordList) => {
          setDataSource(recordList);
        },
        onChange: setEditableRowKeys,
        form: editableFormRef.current,
      }}
    />
  );
};

export default memo(VehicleModel);

🏞 期望结果 | Expected results

setRowData能正常修改数据

💻 复现代码 | Recurrence code

© 版本信息

  • Ant Design Pro 版本: 2.6.22
  • umi 版本 4.0.80
  • 浏览器环境 chrome
  • 开发环境 mac OS

🚑 其他信息

Copy link

以下的 Issues 可能会帮助到你 / The following issues may help you

@Statfine
Copy link
Author

升级版本就可以了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant