Skip to content

Commit

Permalink
fix(table): fix unsuccessful saving of row edit table (#117)
Browse files Browse the repository at this point in the history
Co-authored-by: heresy <Heresy@chxian.com>
  • Loading branch information
LinsRock and heresy authored Dec 7, 2020
1 parent 59ad824 commit 404db2f
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions src/components/Table/src/components/renderEditable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { RenderEditableCellParams } from '../types/table';
import { ComponentType } from '../types/componentType';

import { componentMap } from '../componentMap';
import { isString, isBoolean } from '/@/utils/is';
import { isString, isBoolean, isArray } from '/@/utils/is';
import { FormOutlined, CloseOutlined, CheckOutlined } from '@ant-design/icons-vue';

const prefixCls = 'editable-cell';
Expand Down Expand Up @@ -50,6 +50,7 @@ const EditableCell = defineComponent({
},
placeholder: {
type: String as PropType<string>,
default: '',
},
},
emits: ['submit', 'cancel'],
Expand Down Expand Up @@ -92,9 +93,22 @@ const EditableCell = defineComponent({

if (props.record) {
/* eslint-disable */
props.record.onCancel = handleCancel;
isArray(props.record.submitCbs)
? props.record.submitCbs.push(handleSubmit)
: (props.record.submitCbs = [handleSubmit]);
/* eslint-disable */
isArray(props.record.cancelCbs)
? props.record.cancelCbs.push(handleCancel)
: (props.record.cancelCbs = [handleCancel]);

/* eslint-disable */
props.record.onCancel = () => {
isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
};
/* eslint-disable */
props.record.onSubmit = handleSubmit;
props.record.onSubmit = () => {
isArray(props.record?.submitCbs) && props.record?.submitCbs.forEach((fn) => fn());
};
}

function handleSubmit() {
Expand Down Expand Up @@ -222,4 +236,6 @@ export type EditRecordRow<T = { [key: string]: any }> = {
editable: boolean;
onCancel: Fn;
onSubmit: Fn;
submitCbs: Fn[];
cancelCbs: Fn[];
} & T;

0 comments on commit 404db2f

Please sign in to comment.