Commit df0f00085c1113eddd7a15954818ccece3538068
1 parent
99829c79
fix(table): fix rowSelection.onChange not work
修复为table提供rowSelection.onChange时,无法手动变更table的选中项的问题 fixed: #825
Showing
1 changed file
with
13 additions
and
2 deletions
src/components/Table/src/hooks/useRowSelection.ts
1 | +import { isFunction } from '/@/utils/is'; | |
1 | 2 | import type { BasicTableProps, TableRowSelection } from '../types/table'; |
2 | -import { computed, ref, unref, ComputedRef, Ref, toRaw } from 'vue'; | |
3 | +import { computed, ref, unref, ComputedRef, Ref, toRaw, watch } from 'vue'; | |
3 | 4 | import { ROW_KEY } from '../const'; |
5 | +import { omit } from 'lodash-es'; | |
4 | 6 | |
5 | 7 | export function useRowSelection( |
6 | 8 | propsRef: ComputedRef<BasicTableProps>, |
... | ... | @@ -22,15 +24,24 @@ export function useRowSelection( |
22 | 24 | onChange: (selectedRowKeys: string[], selectedRows: Recordable[]) => { |
23 | 25 | selectedRowKeysRef.value = selectedRowKeys; |
24 | 26 | selectedRowRef.value = selectedRows; |
27 | + const { onChange } = rowSelection; | |
28 | + if (onChange && isFunction(onChange)) onChange(selectedRowKeys, selectedRows); | |
25 | 29 | emit('selection-change', { |
26 | 30 | keys: selectedRowKeys, |
27 | 31 | rows: selectedRows, |
28 | 32 | }); |
29 | 33 | }, |
30 | - ...(rowSelection === undefined ? {} : rowSelection), | |
34 | + ...omit(rowSelection === undefined ? {} : rowSelection, ['onChange']), | |
31 | 35 | }; |
32 | 36 | }); |
33 | 37 | |
38 | + watch( | |
39 | + () => unref(propsRef).rowSelection?.selectedRowKeys, | |
40 | + (v: string[]) => { | |
41 | + selectedRowKeysRef.value = v; | |
42 | + } | |
43 | + ); | |
44 | + | |
34 | 45 | const getAutoCreateKey = computed(() => { |
35 | 46 | return unref(propsRef).autoCreateKey && !unref(propsRef).rowKey; |
36 | 47 | }); | ... | ... |