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