Commit f7a1b022369d535cd0e53fd2a94ffca33664c8a7
Committed by
GitHub
1 parent
0dc2f149
fix(useColumns): 多级表头下的列支持行内编辑 (#2521)
Showing
2 changed files
with
74 additions
and
60 deletions
src/components/Table/src/hooks/useColumns.ts
@@ -146,31 +146,38 @@ export function useColumns( | @@ -146,31 +146,38 @@ export function useColumns( | ||
146 | const getViewColumns = computed(() => { | 146 | const getViewColumns = computed(() => { |
147 | const viewColumns = sortFixedColumn(unref(getColumnsRef)); | 147 | const viewColumns = sortFixedColumn(unref(getColumnsRef)); |
148 | 148 | ||
149 | + const mapFn = (column) => { | ||
150 | + const { slots, customRender, format, edit, editRow, flag } = column; | ||
151 | + | ||
152 | + if (!slots || !slots?.title) { | ||
153 | + // column.slots = { title: `header-${dataIndex}`, ...(slots || {}) }; | ||
154 | + column.customTitle = column.title; | ||
155 | + Reflect.deleteProperty(column, 'title'); | ||
156 | + } | ||
157 | + const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag!); | ||
158 | + if (!customRender && format && !edit && !isDefaultAction) { | ||
159 | + column.customRender = ({ text, record, index }) => { | ||
160 | + return formatCell(text, format, record, index); | ||
161 | + }; | ||
162 | + } | ||
163 | + | ||
164 | + // edit table | ||
165 | + if ((edit || editRow) && !isDefaultAction) { | ||
166 | + column.customRender = renderEditCell(column); | ||
167 | + } | ||
168 | + return reactive(column); | ||
169 | + }; | ||
170 | + | ||
149 | const columns = cloneDeep(viewColumns); | 171 | const columns = cloneDeep(viewColumns); |
150 | return columns | 172 | return columns |
151 | - .filter((column) => { | ||
152 | - return hasPermission(column.auth) && isIfShow(column); | ||
153 | - }) | 173 | + .filter((column) => hasPermission(column.auth) && isIfShow(column)) |
154 | .map((column) => { | 174 | .map((column) => { |
155 | - const { slots, customRender, format, edit, editRow, flag } = column; | ||
156 | - | ||
157 | - if (!slots || !slots?.title) { | ||
158 | - // column.slots = { title: `header-${dataIndex}`, ...(slots || {}) }; | ||
159 | - column.customTitle = column.title; | ||
160 | - Reflect.deleteProperty(column, 'title'); | ||
161 | - } | ||
162 | - const isDefaultAction = [INDEX_COLUMN_FLAG, ACTION_COLUMN_FLAG].includes(flag!); | ||
163 | - if (!customRender && format && !edit && !isDefaultAction) { | ||
164 | - column.customRender = ({ text, record, index }) => { | ||
165 | - return formatCell(text, format, record, index); | ||
166 | - }; | 175 | + // Support table multiple header editable |
176 | + if (column.children?.length) { | ||
177 | + column.children = column.children.map(mapFn); | ||
167 | } | 178 | } |
168 | 179 | ||
169 | - // edit table | ||
170 | - if ((edit || editRow) && !isDefaultAction) { | ||
171 | - column.customRender = renderEditCell(column); | ||
172 | - } | ||
173 | - return reactive(column); | 180 | + return mapFn(column); |
174 | }); | 181 | }); |
175 | }); | 182 | }); |
176 | 183 |
src/views/demo/table/EditRowTable.vue
@@ -29,47 +29,54 @@ | @@ -29,47 +29,54 @@ | ||
29 | const columns: BasicColumn[] = [ | 29 | const columns: BasicColumn[] = [ |
30 | { | 30 | { |
31 | title: '输入框', | 31 | title: '输入框', |
32 | - dataIndex: 'name', | 32 | + dataIndex: 'name-group', |
33 | editRow: true, | 33 | editRow: true, |
34 | - editComponentProps: { | ||
35 | - prefix: '$', | ||
36 | - }, | ||
37 | - width: 150, | ||
38 | - }, | ||
39 | - { | ||
40 | - title: '默认输入状态', | ||
41 | - dataIndex: 'name7', | ||
42 | - editRow: true, | ||
43 | - width: 150, | ||
44 | - }, | ||
45 | - { | ||
46 | - title: '输入框校验', | ||
47 | - dataIndex: 'name1', | ||
48 | - editRow: true, | ||
49 | - align: 'left', | ||
50 | - // 默认必填校验 | ||
51 | - editRule: true, | ||
52 | - width: 150, | ||
53 | - }, | ||
54 | - { | ||
55 | - title: '输入框函数校验', | ||
56 | - dataIndex: 'name2', | ||
57 | - editRow: true, | ||
58 | - align: 'right', | ||
59 | - editRule: async (text) => { | ||
60 | - if (text === '2') { | ||
61 | - return '不能输入该值'; | ||
62 | - } | ||
63 | - return ''; | ||
64 | - }, | ||
65 | - }, | ||
66 | - { | ||
67 | - title: '数字输入框', | ||
68 | - dataIndex: 'id', | ||
69 | - editRow: true, | ||
70 | - editRule: true, | ||
71 | - editComponent: 'InputNumber', | ||
72 | - width: 150, | 34 | + children: [ |
35 | + { | ||
36 | + title: '输入框', | ||
37 | + dataIndex: 'name', | ||
38 | + editRow: true, | ||
39 | + editComponentProps: { | ||
40 | + prefix: '$', | ||
41 | + }, | ||
42 | + width: 150, | ||
43 | + }, | ||
44 | + { | ||
45 | + title: '默认输入状态', | ||
46 | + dataIndex: 'name7', | ||
47 | + editRow: true, | ||
48 | + width: 150, | ||
49 | + }, | ||
50 | + { | ||
51 | + title: '输入框校验', | ||
52 | + dataIndex: 'name1', | ||
53 | + editRow: true, | ||
54 | + align: 'left', | ||
55 | + // 默认必填校验 | ||
56 | + editRule: true, | ||
57 | + width: 150, | ||
58 | + }, | ||
59 | + { | ||
60 | + title: '输入框函数校验', | ||
61 | + dataIndex: 'name2', | ||
62 | + editRow: true, | ||
63 | + align: 'right', | ||
64 | + editRule: async (text) => { | ||
65 | + if (text === '2') { | ||
66 | + return '不能输入该值'; | ||
67 | + } | ||
68 | + return ''; | ||
69 | + }, | ||
70 | + }, | ||
71 | + { | ||
72 | + title: '数字输入框', | ||
73 | + dataIndex: 'id', | ||
74 | + editRow: true, | ||
75 | + editRule: true, | ||
76 | + editComponent: 'InputNumber', | ||
77 | + width: 150, | ||
78 | + }, | ||
79 | + ], | ||
73 | }, | 80 | }, |
74 | { | 81 | { |
75 | title: '下拉框', | 82 | title: '下拉框', |