Skip to content

Commit

Permalink
feat(table): support custom update on row editing
Browse files Browse the repository at this point in the history
在表格进入行编辑状态时,在某一列数据发生修改时,允许获取或同步修改其它列的当前编辑数据。

close #646
  • Loading branch information
mynetfan committed Jun 5, 2021
1 parent 808012b commit fe2bcfc
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/components/Table/src/components/editable/EditableCell.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@
initCbs('validCbs', handleSubmiRule);
initCbs('cancelCbs', handleCancel);
if (props.column.dataIndex) {
if (!props.record.editValueRefs) props.record.editValueRefs = {};
props.record.editValueRefs[props.column.dataIndex] = currentValueRef;
}
/* eslint-disable */
props.record.onCancelEdit = () => {
isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
Expand Down
3 changes: 2 additions & 1 deletion src/components/Table/src/components/editable/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BasicColumn } from '/@/components/Table/src/types/table';

import { h } from 'vue';
import { h, Ref } from 'vue';

import EditableCell from './EditableCell.vue';

Expand Down Expand Up @@ -50,5 +50,6 @@ export type EditRecordRow<T = Recordable> = Partial<
submitCbs: Fn[];
cancelCbs: Fn[];
validCbs: Fn[];
editValueRefs: Recordable<Ref>;
} & T
>;
14 changes: 13 additions & 1 deletion src/views/demo/table/EditRowTable.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<div class="p-4">
<BasicTable @register="registerTable">
<BasicTable @register="registerTable" @edit-change="onEditChange">
<template #action="{ record, column }">
<TableAction :actions="createActions(record, column)" />
</template>
Expand Down Expand Up @@ -145,6 +145,9 @@
const [registerTable] = useTable({
title: '可编辑行示例',
titleHelpMessage: [
'本例中修改[数字输入框]这一列时,同一行的[远程下拉]列的当前编辑数据也会同步发生改变',
],
api: demoListApi,
columns: columns,
showIndexColumn: false,
Expand Down Expand Up @@ -198,10 +201,19 @@
];
}
function onEditChange({ column, value, record }) {
// 本例
if (column.dataIndex === 'id') {
record.editValueRefs.name4.value = `${value}`;
}
console.log(column, value, record);
}
return {
registerTable,
handleEdit,
createActions,
onEditChange,
};
},
});
Expand Down

0 comments on commit fe2bcfc

Please sign in to comment.