Commit fe2bcfc6f74159c355f3be153a316869fdb8b644
1 parent
808012b5
feat(table): support custom update on row editing
在表格进入行编辑状态时,在某一列数据发生修改时,允许获取或同步修改其它列的当前编辑数据。 close #646
Showing
3 changed files
with
19 additions
and
2 deletions
src/components/Table/src/components/editable/EditableCell.vue
@@ -282,6 +282,10 @@ | @@ -282,6 +282,10 @@ | ||
282 | initCbs('validCbs', handleSubmiRule); | 282 | initCbs('validCbs', handleSubmiRule); |
283 | initCbs('cancelCbs', handleCancel); | 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 | /* eslint-disable */ | 289 | /* eslint-disable */ |
286 | props.record.onCancelEdit = () => { | 290 | props.record.onCancelEdit = () => { |
287 | isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn()); | 291 | isArray(props.record?.cancelCbs) && props.record?.cancelCbs.forEach((fn) => fn()); |
src/components/Table/src/components/editable/index.ts
1 | import type { BasicColumn } from '/@/components/Table/src/types/table'; | 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 | import EditableCell from './EditableCell.vue'; | 5 | import EditableCell from './EditableCell.vue'; |
6 | 6 | ||
@@ -50,5 +50,6 @@ export type EditRecordRow<T = Recordable> = Partial< | @@ -50,5 +50,6 @@ export type EditRecordRow<T = Recordable> = Partial< | ||
50 | submitCbs: Fn[]; | 50 | submitCbs: Fn[]; |
51 | cancelCbs: Fn[]; | 51 | cancelCbs: Fn[]; |
52 | validCbs: Fn[]; | 52 | validCbs: Fn[]; |
53 | + editValueRefs: Recordable<Ref>; | ||
53 | } & T | 54 | } & T |
54 | >; | 55 | >; |
src/views/demo/table/EditRowTable.vue
1 | <template> | 1 | <template> |
2 | <div class="p-4"> | 2 | <div class="p-4"> |
3 | - <BasicTable @register="registerTable"> | 3 | + <BasicTable @register="registerTable" @edit-change="onEditChange"> |
4 | <template #action="{ record, column }"> | 4 | <template #action="{ record, column }"> |
5 | <TableAction :actions="createActions(record, column)" /> | 5 | <TableAction :actions="createActions(record, column)" /> |
6 | </template> | 6 | </template> |
@@ -145,6 +145,9 @@ | @@ -145,6 +145,9 @@ | ||
145 | 145 | ||
146 | const [registerTable] = useTable({ | 146 | const [registerTable] = useTable({ |
147 | title: '可编辑行示例', | 147 | title: '可编辑行示例', |
148 | + titleHelpMessage: [ | ||
149 | + '本例中修改[数字输入框]这一列时,同一行的[远程下拉]列的当前编辑数据也会同步发生改变', | ||
150 | + ], | ||
148 | api: demoListApi, | 151 | api: demoListApi, |
149 | columns: columns, | 152 | columns: columns, |
150 | showIndexColumn: false, | 153 | showIndexColumn: false, |
@@ -198,10 +201,19 @@ | @@ -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 | return { | 212 | return { |
202 | registerTable, | 213 | registerTable, |
203 | handleEdit, | 214 | handleEdit, |
204 | createActions, | 215 | createActions, |
216 | + onEditChange, | ||
205 | }; | 217 | }; |
206 | }, | 218 | }, |
207 | }); | 219 | }); |