Skip to content

Commit

Permalink
fix(table): fix edit.on.onChange is invalidate (#2374)
Browse files Browse the repository at this point in the history
  • Loading branch information
chaishi authored Feb 11, 2023
1 parent eb49d64 commit 15992e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
5 changes: 5 additions & 0 deletions src/table/_example/editable-cell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ const columns = computed(() => [
clearable: true,
options: STATUS_OPTIONS,
},
on: (editContext) => ({
onChange: (params) => {
console.log('status changed', editContext, params);
},
}),
// 除了点击非自身元素退出编辑态之外,还有哪些事件退出编辑态
abortEditOnEvent: ['onChange'],
// 编辑完成,退出编辑态后触发
Expand Down
8 changes: 7 additions & 1 deletion src/table/editable-cell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ export default defineComponent({
const errorList = ref<AllValidateResult[]>();

const { Edit1Icon } = useGlobalIcon({ Edit1Icon: TdEdit1Icon });
const editOnListeners = computed(() => {
return col.value.edit?.on?.({ ...cellParams.value, editedRow: currentRow.value });
});

const cellParams = computed(() => ({
rowIndex: props.rowIndex,
Expand Down Expand Up @@ -234,6 +237,7 @@ export default defineComponent({
};
props.onChange?.(params);
props.onRuleChange?.(params);
editOnListeners.value?.onChange?.(params);
const isCellEditable = props.editable === undefined;
if (isCellEditable && isAbortEditOnChange.value) {
const outsideAbortEvent = col.value.edit?.onEdited;
Expand Down Expand Up @@ -349,6 +353,8 @@ export default defineComponent({
return null;
}
const errorMessage = errorList.value?.[0]?.message;
const tmpEditOnListeners = { ...editOnListeners.value };
delete tmpEditOnListeners.onChange;
return (
<div
class={props.tableBaseClass.cellEditWrap}
Expand All @@ -362,7 +368,7 @@ export default defineComponent({
tips={errorMessage}
{...componentProps.value}
{...listeners.value}
{...col.value.edit?.on?.({ ...cellParams.value, editedRow: currentRow.value })}
{...tmpEditOnListeners}
value={editValue.value}
onChange={onEditChange}
/>
Expand Down

0 comments on commit 15992e7

Please sign in to comment.