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] EditableProTable 没有name属性,只能新增一行 #6279

Closed
rawbin- opened this issue Nov 25, 2022 · 6 comments
Closed

🐛[BUG] EditableProTable 没有name属性,只能新增一行 #6279

rawbin- opened this issue Nov 25, 2022 · 6 comments

Comments

@rawbin-
Copy link
Contributor

rawbin- commented Nov 25, 2022

🐛 bug 描述

Editable没有name属性时,报只能新增一行,增加name属性后ok

📷 复现步骤

https://codesandbox.io/s/shi-shi-bao-cun-de-bian-ji-biao-ge-forked-v9jxgd?file=/App.tsx:620-1731

demo版本:

  • 不设置 newRecordType, 设置name可以无限添加但无法带入初始数据,不设name能带入初始数据提示只能新增一条
  • 设置newRecoordType, 加name行数据会动态更新但无法带入初始数据,不加name行数据不动态更新但editable.onChange会变,editable.onValuesChange不变且能带入初始数据

本地版本(pro-table 2.56.9):

  • 不设置 newRecordType,加不加name都只能一行,不加name能带入初始数据
  • 设置newRecoordType, 加name行数据会动态更新但无法带入初始数据,不加name行数据不动态更新但editable.onChange会变,editable.onValuesChange不变且能带入初始数据
export default (props: ProTableProps<any, any>) => {
  const [editableKeys, setEditibleKeys] = useState(['xx'])
  return <EditableProTable
    columns={[{
      title: '参数名',
      dataIndex: 'name'
    }, {
      title: '参数类型',
      dataIndex: 'type'
    }, {
      title: '参数值',
      dataIndex: 'value'
    }]}
    // value={[{ id: 'xx' }]} // 同 dataSource
    name="xxx"   // 有这个属性可以无限增加,没有这个属性会报只能增加一行
    rowKey='id'
    recordCreatorProps={{
      record: {id:+new Date()}
    }}
    // recordCreatorProps={false}
    onChange={(value) => {
      console.log('table value change:', value)
    }}
    editable={{
      type: 'multiple',
      editableKeys: editableKeys,
      onValuesChange: (record, recordList) => {
        console.log('values change:', record, recordList)
      },
      onChange: (editableKeys, editableRows) => {
        console.log('editable value change', editableKeys, editableRows)
        setEditibleKeys(editableKeys)
      },
      actionRender: (row, config, defaultDom) => {
        console.log('actionRender:', row, config, defaultDom)
      }
    }}
    {
      ...props
    }
  ></EditableProTable>
}

🏞 期望结果

有没有name属性,都能带入初始数据,并且能文档说明这个单行限制

💻 复现代码

© 版本信息

  • ProComponents 版本: [e.g. 4.0.0]
  • umi 版本
  • 浏览器环境
  • 开发环境 [e.g. mac OS]

🚑 其他信息

@github-actions
Copy link

github-actions bot commented Nov 25, 2022

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

@rawbin-
Copy link
Contributor Author

rawbin- commented Nov 25, 2022

本地版本和demo版本行为还不一致,本地是一年前的版本,然后demo是最新版,差异比较大

pro-components相关的更新,会涉及到antd的更新,而这一波连带更新,搞完之后就不知道会出现什么结果,比如记得有个ProFormList不同版本的行为字段会有比较大的差别,加上ProComponents的文档本身也不够详细,有些字段需要demo或者源码里面翻,这个有什么建议么~

@chenshuai2144
Copy link
Contributor

搞个重现吧,尽量用最新版本的版本,过去的版本不一定能配合好 antd 版本

@cangsnage
Copy link

export default (props: ProTableProps<any, any>) => {
const [editableKeys, setEditibleKeys] = useState(['xx'])
return <EditableProTable
columns={[{
title: '参数名',
dataIndex: 'name'
}, {
title: '参数类型',
dataIndex: 'type'
}, {
title: '参数值',
dataIndex: 'value'
}]}
// value={[{ id: 'xx' }]} // 同 dataSource
name="xxx" // 有这个属性可以无限增加,没有这个属性会报只能增加一行
rowKey='id'
recordCreatorProps={{
record: {id:+new Date()}
}}
// recordCreatorProps={false}
onChange={(value) => {
console.log('table value change:', value)
}}
editable={{
type: 'multiple',
editableKeys: editableKeys,
onValuesChange: (record, recordList) => {
console.log('values change:', record, recordList)
},
onChange: (editableKeys, editableRows) => {
console.log('editable value change', editableKeys, editableRows)
setEditibleKeys(editableKeys)
},
actionRender: (row, config, defaultDom) => {
console.log('actionRender:', row, config, defaultDom)
}
}}
{

如果自定义按钮使用actionRef 怎么进行新增一行,继续新增呢

@chenshuai2144
Copy link
Contributor

设计就是这样的,如果要自己控制最好用name

@kaindy7633
Copy link

recordCreatorProps={{
        position: 'bottom',
        newRecordType: 'dataSource',
        record: () => ({ id: (Math.random() * 1000000).toFixed(0) }),
}}

没有配置name,name不好控制,我在 dnd-kit 中使用

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

4 participants