Commit 404db2fb4975c69851dbf73a9ea8f981fb0ddb56
Committed by
GitHub
1 parent
59ad8244
fix(table): fix unsuccessful saving of row edit table (#117)
Co-authored-by: heresy <Heresy@chxian.com>
Showing
1 changed file
with
19 additions
and
3 deletions
src/components/Table/src/components/renderEditable.tsx
... | ... | @@ -7,7 +7,7 @@ import { RenderEditableCellParams } from '../types/table'; |
7 | 7 | import { ComponentType } from '../types/componentType'; |
8 | 8 | |
9 | 9 | import { componentMap } from '../componentMap'; |
10 | -import { isString, isBoolean } from '/@/utils/is'; | |
10 | +import { isString, isBoolean, isArray } from '/@/utils/is'; | |
11 | 11 | import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue'; |
12 | 12 | |
13 | 13 | const prefixCls = 'editable-cell'; |
... | ... | @@ -50,6 +50,7 @@ const EditableCell = defineComponent({ |
50 | 50 | }, |
51 | 51 | placeholder: { |
52 | 52 | type: String as PropType<string>, |
53 | + default: '', | |
53 | 54 | }, |
54 | 55 | }, |
55 | 56 | emits: ['submit', 'cancel'], |
... | ... | @@ -92,9 +93,22 @@ const EditableCell = defineComponent({ |
92 | 93 | |
93 | 94 | if (props.record) { |
94 | 95 | /* eslint-disable */ |
95 | - props.record.onCancel = handleCancel; | |
96 | + isArray(props.record.submitCbs) | |
97 | + ? props.record.submitCbs.push(handleSubmit) | |
98 | + : (props.record.submitCbs = [handleSubmit]); | |
99 | + /* eslint-disable */ | |
100 | + isArray(props.record.cancelCbs) | |
101 | + ? props.record.cancelCbs.push(handleCancel) | |
102 | + : (props.record.cancelCbs = [handleCancel]); | |
103 | + | |
104 | + /* eslint-disable */ | |
105 | + props.record.onCancel = () => { | |
106 | + isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn()); | |
107 | + }; | |
96 | 108 | /* eslint-disable */ |
97 | - props.record.onSubmit = handleSubmit; | |
109 | + props.record.onSubmit = () => { | |
110 | + isArray(props.record?.submitCbs) && props.record?.submitCbs.forEach((fn) => fn()); | |
111 | + }; | |
98 | 112 | } |
99 | 113 | |
100 | 114 | function handleSubmit() { |
... | ... | @@ -222,4 +236,6 @@ export type EditRecordRow<T = { [key: string]: any }> = { |
222 | 236 | editable: boolean; |
223 | 237 | onCancel: Fn; |
224 | 238 | onSubmit: Fn; |
239 | + submitCbs: Fn[]; | |
240 | + cancelCbs: Fn[]; | |
225 | 241 | } & T; | ... | ... |