Commit 404db2fb4975c69851dbf73a9ea8f981fb0ddb56

Authored by Heresy
Committed by GitHub
1 parent 59ad8244

fix(table): fix unsuccessful saving of row edit table (#117)

Co-authored-by: heresy <Heresy@chxian.com>
src/components/Table/src/components/renderEditable.tsx
@@ -7,7 +7,7 @@ import { RenderEditableCellParams } from &#39;../types/table&#39;; @@ -7,7 +7,7 @@ import { RenderEditableCellParams } from &#39;../types/table&#39;;
7 import { ComponentType } from '../types/componentType'; 7 import { ComponentType } from '../types/componentType';
8 8
9 import { componentMap } from '../componentMap'; 9 import { componentMap } from '../componentMap';
10 -import { isString, isBoolean } from '/@/utils/is'; 10 +import { isString, isBoolean, isArray } from '/@/utils/is';
11 import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue'; 11 import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue';
12 12
13 const prefixCls = 'editable-cell'; 13 const prefixCls = 'editable-cell';
@@ -50,6 +50,7 @@ const EditableCell = defineComponent({ @@ -50,6 +50,7 @@ const EditableCell = defineComponent({
50 }, 50 },
51 placeholder: { 51 placeholder: {
52 type: String as PropType<string>, 52 type: String as PropType<string>,
  53 + default: '',
53 }, 54 },
54 }, 55 },
55 emits: ['submit', 'cancel'], 56 emits: ['submit', 'cancel'],
@@ -92,9 +93,22 @@ const EditableCell = defineComponent({ @@ -92,9 +93,22 @@ const EditableCell = defineComponent({
92 93
93 if (props.record) { 94 if (props.record) {
94 /* eslint-disable */ 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 /* eslint-disable */ 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 function handleSubmit() { 114 function handleSubmit() {
@@ -222,4 +236,6 @@ export type EditRecordRow&lt;T = { [key: string]: any }&gt; = { @@ -222,4 +236,6 @@ export type EditRecordRow&lt;T = { [key: string]: any }&gt; = {
222 editable: boolean; 236 editable: boolean;
223 onCancel: Fn; 237 onCancel: Fn;
224 onSubmit: Fn; 238 onSubmit: Fn;
  239 + submitCbs: Fn[];
  240 + cancelCbs: Fn[];
225 } & T; 241 } & T;