From 07dea346dc4b3270b4d5d0a6b573371e9c34b502 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A4=D1=80=D0=BE=D0=BB=D0=BE=D0=B2?= Date: Thu, 12 Aug 2021 15:41:11 +0500 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D1=82=D1=8C=20=D0=B8=D0=BD=D0=B8=D1=86=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=82=D1=8C=20?= =?UTF-8?q?=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/EditableTable.jsx | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/components/EditableTable.jsx b/src/components/EditableTable.jsx index 9550752..2062a63 100644 --- a/src/components/EditableTable.jsx +++ b/src/components/EditableTable.jsx @@ -14,6 +14,7 @@ const EditableCell = ({ formItemClass, formItemRules, children, + initialValue, }) => { const inputNode = input ?? @@ -26,7 +27,8 @@ const EditableCell = ({ name={dataIndex} style={{margin:0}} className={formItemClass} - rules={rules}> + rules={rules} + initialValue={initialValue}> {inputNode} @@ -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, }), } }