ant-design / ant-design/pro-components

🐛[BUG] EditableTable.recordCreatorProps.record函数触发时机问题

Open
#8,174 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
4.8k
Forks
1.4k
Avg merge
10h 44m
Merged PRs (30d)
3

Description

### 🐛 bug 描述

EditableTable.recordCreatorProps.record函数会在按钮挂载的时候就预生成了要添加的行数据,并且后面每次点击按钮生成的行数据是在上一次按钮的时候的生成的,这点有点反直觉,是否考虑调整一下?
[问题代码位置](https://github.com/ant-design/pro-components/blob/master/packages/table/src/components/EditableTable/index.tsx#L339)

### 🏞 期望结果
在点击按钮时才生成当前的行数据

### 💻 复现代码
```tsx
export default () => {
const columns: ProColumns[] = [
{
title: "index",
dataIndex: "idx",
width: "30%",
editable: false,
},
{
title: "创建时间",
dataIndex: "created_at",
valueType: "dateTime",
renderText(text, record, index, action) {
return dayjs(text).format("YYYY-MM-DD HH:mm:ss");
},
editable: false,
},
];

return (

rowKey="id"
recordCreatorProps={{
newRecordType: "dataSource",
record: (idx) => {
const newRecord = {
idx,
id: (Math.random() * 1000000).toFixed(0),
created_at: dayjs().valueOf(),
};
console.log(`generate ${idx} row data:`, newRecord);
return newRecord;
},
}}
columns={columns}
editable={{
type: "multiple",
}}
/>
);
};
```
### © 版本信息

- ProComponents 版本: 2.6.49

### 截图

![image](https://github.com/ant-design/pro-components/assets/6702568/73226fd6-cb32-4d55-be49-fa6dae824152)

Contributor guide

Open the contributing guide

Research direction

Start in packages/table/src/components/EditableTable/index.tsx around line 339 and reproduce the behavior with the provided record callback. Check when the callback runs relative to mounting and clicking the record-creation button. Done means each click generates the new row data at click time rather than reusing data generated earlier.

Written by the indexing model from the issue text.

Assessment

Tech stack
react, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.