Commit fe2bcfc6f74159c355f3be153a316869fdb8b644

Authored by 无木
1 parent 808012b5

feat(table): support custom update on row editing

在表格进入行编辑状态时,在某一列数据发生修改时,允许获取或同步修改其它列的当前编辑数据。

close #646
src/components/Table/src/components/editable/EditableCell.vue
... ... @@ -282,6 +282,10 @@
282 282 initCbs('validCbs', handleSubmiRule);
283 283 initCbs('cancelCbs', handleCancel);
284 284  
  285 + if (props.column.dataIndex) {
  286 + if (!props.record.editValueRefs) props.record.editValueRefs = {};
  287 + props.record.editValueRefs[props.column.dataIndex] = currentValueRef;
  288 + }
285 289 /* eslint-disable */
286 290 props.record.onCancelEdit = () => {
287 291 isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn());
... ...
src/components/Table/src/components/editable/index.ts
1 1 import type { BasicColumn } from '/@/components/Table/src/types/table';
2 2  
3   -import { h } from 'vue';
  3 +import { h, Ref } from 'vue';
4 4  
5 5 import EditableCell from './EditableCell.vue';
6 6  
... ... @@ -50,5 +50,6 @@ export type EditRecordRow<T = Recordable> = Partial<
50 50 submitCbs: Fn[];
51 51 cancelCbs: Fn[];
52 52 validCbs: Fn[];
  53 + editValueRefs: Recordable<Ref>;
53 54 } & T
54 55 >;
... ...
src/views/demo/table/EditRowTable.vue
1 1 <template>
2 2 <div class="p-4">
3   - <BasicTable @register="registerTable">
  3 + <BasicTable @register="registerTable" @edit-change="onEditChange">
4 4 <template #action="{ record, column }">
5 5 <TableAction :actions="createActions(record, column)" />
6 6 </template>
... ... @@ -145,6 +145,9 @@
145 145  
146 146 const [registerTable] = useTable({
147 147 title: '可编辑行示例',
  148 + titleHelpMessage: [
  149 + '本例中修改[数字输入框]这一列时,同一行的[远程下拉]列的当前编辑数据也会同步发生改变',
  150 + ],
148 151 api: demoListApi,
149 152 columns: columns,
150 153 showIndexColumn: false,
... ... @@ -198,10 +201,19 @@
198 201 ];
199 202 }
200 203  
  204 + function onEditChange({ column, value, record }) {
  205 + // 本例
  206 + if (column.dataIndex === 'id') {
  207 + record.editValueRefs.name4.value = `${value}`;
  208 + }
  209 + console.log(column, value, record);
  210 + }
  211 +
201 212 return {
202 213 registerTable,
203 214 handleEdit,
204 215 createActions,
  216 + onEditChange,
205 217 };
206 218 },
207 219 });
... ...