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

antd table 的 ExpandedRowRender是一个表单,当默认展开的时候,对表单进行赋值的时候,总是会对最后一个表单赋值。 #48670

Closed
liushuhui opened this issue Apr 27, 2024 · 2 comments

Comments

@liushuhui
Copy link

Reproduction link

https://react-21qt77.stackblitz.io/

Steps to reproduce

import { Table, Badge, Menu, Dropdown, Input, Form, Select } from "antd";
import { useState } from "react";

const { Option } = Select;
export default () => {
const [value, setValue] = useState("");
const expandedRowRender = () => {
const handleChange = (e) => {
setValue(e);
};
return (
<>
<Select style={{ width: 120 }} onChange={handleChange}>
Jack
Lucy

Disabled

yiminghe


</>
);
};

const columns = [
{ title: "Name", dataIndex: "name", key: "name" },
{ title: "Platform", dataIndex: "platform", key: "platform" },
{ title: "Version", dataIndex: "version", key: "version" },
{ title: "Upgraded", dataIndex: "upgradeNum", key: "upgradeNum" },
{ title: "Creator", dataIndex: "creator", key: "creator" },
{ title: "Date", dataIndex: "createdAt", key: "createdAt" },
{ title: "Action", key: "operation", render: () => Publish },
];

const data = [];
for (let i = 0; i < 3; i) {
data.push({
key: i,
name: "Screem",
platform: "iOS",
version: "10.3.4.5654",
upgradeNum: 500,
creator: "Jack",
createdAt: "2014-12-24 23:12:00",
});
}

return (
<Table
rowKey='key'
className="components-table-demo-nested"
columns={columns}
expandable={{
expandedRowRender: expandedRowRender,
}}
dataSource={data}
/>
);
};

What is expected?

demo是一个简化版的需求,expandedRowRender返回的是一个表单,默认全部展开的情况下,当我对相应表单进行form.setFieldValue操作的时候,只是修改当前行的数据。而不影响其他的行的表单数据

What is actually happening?

demo是一个简化版的需求,expandedRowRender返回的是一个表单,默认全部展开的情况下,当我对相应表单进行form.setFieldValue操作的时候,假如有两行,我修改第一行或者第二行的表单值的时候,都会映射到第三行的表单去,也就是说对表单进行赋值的时候,总是会对最后一个表单赋值。

Environment Info
antd undefined
React 16.x
System widnow
Browser 谷歌
@liushuhui
Copy link
Author

实际场景如下:父组件:
image
子组件:
image

@afc163
Copy link
Member

afc163 commented Apr 29, 2024

这样写相当于三个 Select 共用了一份 value 状态,肯定是一改都改了。你需要把状态隔离到各个子组件中。

@afc163 afc163 closed this as completed Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants