forked from ddrilling/asb_cloud_front
возможность инициализировать данные
This commit is contained in:
parent
5038285d6d
commit
07dea346dc
@ -14,6 +14,7 @@ const EditableCell = ({
|
||||
formItemClass,
|
||||
formItemRules,
|
||||
children,
|
||||
initialValue,
|
||||
}) => {
|
||||
|
||||
const inputNode = input ?? <Input/>
|
||||
@ -26,7 +27,8 @@ const EditableCell = ({
|
||||
name={dataIndex}
|
||||
style={{margin:0}}
|
||||
className={formItemClass}
|
||||
rules={rules}>
|
||||
rules={rules}
|
||||
initialValue={initialValue}>
|
||||
{inputNode}
|
||||
</Form.Item>
|
||||
|
||||
@ -70,8 +72,9 @@ export const EditableTable = ({
|
||||
setEditingKey('')
|
||||
}
|
||||
|
||||
const addNewRow = () => {
|
||||
const addNewRow = async () => {
|
||||
let newRow = {
|
||||
...form.initialValues,
|
||||
key:newRowKeyValue
|
||||
}
|
||||
const newData = [...data, newRow]
|
||||
@ -84,9 +87,10 @@ export const EditableTable = ({
|
||||
const row = await form.validateFields()
|
||||
const newData = [...data]
|
||||
const index = newData.findIndex((item) => record.key === item.key)
|
||||
let item = newData[index]
|
||||
const item = newData[index]
|
||||
const newItem = { ...item, ...row }
|
||||
|
||||
newData.splice(index, 1, { ...item, ...row })
|
||||
newData.splice(index, 1, newItem)
|
||||
|
||||
if(item.key === newRowKeyValue)
|
||||
item.key = newRowKeyValue + newData.length
|
||||
@ -95,9 +99,9 @@ export const EditableTable = ({
|
||||
setData(newData)
|
||||
|
||||
if (editingKey === newRowKeyValue)
|
||||
onRowAdd(item)
|
||||
onRowAdd(newItem)
|
||||
else
|
||||
onRowEdit(item)
|
||||
onRowEdit(newItem)
|
||||
|
||||
if(onChange)
|
||||
onChange(newData)
|
||||
@ -170,6 +174,7 @@ export const EditableTable = ({
|
||||
dataType: col.dataType,
|
||||
formItemClass: col.formItemClass,
|
||||
formItemRules: col.formItemRules,
|
||||
initialValue: col.initialValue,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user