Commit 0dc2f1496b00b941375772345efb262dea74364c
Committed by
GitHub
1 parent
dab977ff
fix: 合并单元格页面 由于 ant-design-vue 升级 v3 版本,页面报 Warning: columns.customRender 即将废弃,c…
…olumns.customRender 用 columns. customCell 替换 (#2520) * fix(MergeHeader): 组件/Table/合并单元格页面 修改 Tabel.title 值为 合并单元格、修改 Table.bordered 值为 true 更好显示合并单元格效果 * fix(tableData): 由于 ant-design-vue 升级 v3 版本,页面报 Warning: columns.customRender 即将废弃
Showing
2 changed files
with
18 additions
and
29 deletions
src/views/demo/table/MergeHeader.vue
@@ -14,7 +14,8 @@ | @@ -14,7 +14,8 @@ | ||
14 | components: { BasicTable }, | 14 | components: { BasicTable }, |
15 | setup() { | 15 | setup() { |
16 | const [registerTable] = useTable({ | 16 | const [registerTable] = useTable({ |
17 | - title: '多级表头示例', | 17 | + title: '合并单元格', |
18 | + bordered: true, | ||
18 | api: demoListApi, | 19 | api: demoListApi, |
19 | columns: getMergeHeaderColumns(), | 20 | columns: getMergeHeaderColumns(), |
20 | }); | 21 | }); |
src/views/demo/table/tableData.tsx
@@ -157,29 +157,26 @@ export function getCustomHeaderColumns(): BasicColumn[] { | @@ -157,29 +157,26 @@ export function getCustomHeaderColumns(): BasicColumn[] { | ||
157 | }, | 157 | }, |
158 | ]; | 158 | ]; |
159 | } | 159 | } |
160 | -const renderContent = ({ text, index }: { text: any; index: number }) => { | ||
161 | - const obj: any = { | ||
162 | - children: text, | ||
163 | - attrs: {}, | ||
164 | - }; | ||
165 | - if (index === 9) { | ||
166 | - obj.attrs.colSpan = 0; | ||
167 | - } | ||
168 | - return obj; | ||
169 | -}; | 160 | + |
161 | +const cellContent = (_, index) => ({ | ||
162 | + colSpan: index === 9 ? 0 : 1, | ||
163 | +}); | ||
164 | + | ||
170 | export function getMergeHeaderColumns(): BasicColumn[] { | 165 | export function getMergeHeaderColumns(): BasicColumn[] { |
171 | return [ | 166 | return [ |
172 | { | 167 | { |
173 | title: 'ID', | 168 | title: 'ID', |
174 | dataIndex: 'id', | 169 | dataIndex: 'id', |
175 | width: 300, | 170 | width: 300, |
176 | - customRender: renderContent, | 171 | + customCell: (_, index) => ({ |
172 | + colSpan: index === 9 ? 6 : 1, | ||
173 | + }), | ||
177 | }, | 174 | }, |
178 | { | 175 | { |
179 | title: '姓名', | 176 | title: '姓名', |
180 | dataIndex: 'name', | 177 | dataIndex: 'name', |
181 | width: 300, | 178 | width: 300, |
182 | - customRender: renderContent, | 179 | + customCell: cellContent, |
183 | }, | 180 | }, |
184 | { | 181 | { |
185 | title: '地址', | 182 | title: '地址', |
@@ -187,19 +184,10 @@ export function getMergeHeaderColumns(): BasicColumn[] { | @@ -187,19 +184,10 @@ export function getMergeHeaderColumns(): BasicColumn[] { | ||
187 | colSpan: 2, | 184 | colSpan: 2, |
188 | width: 120, | 185 | width: 120, |
189 | sorter: true, | 186 | sorter: true, |
190 | - customRender: ({ text, index }: { text: any; index: number }) => { | ||
191 | - const obj: any = { | ||
192 | - children: text, | ||
193 | - attrs: {}, | ||
194 | - }; | ||
195 | - if (index === 2) { | ||
196 | - obj.attrs.rowSpan = 2; | ||
197 | - } | ||
198 | - if (index === 3) { | ||
199 | - obj.attrs.colSpan = 0; | ||
200 | - } | ||
201 | - return obj; | ||
202 | - }, | 187 | + customCell: (_, index) => ({ |
188 | + rowSpan: index === 2 ? 2 : 1, | ||
189 | + colSpan: index === 3 || index === 9 ? 0 : 1, | ||
190 | + }), | ||
203 | }, | 191 | }, |
204 | { | 192 | { |
205 | title: '编号', | 193 | title: '编号', |
@@ -209,19 +197,19 @@ export function getMergeHeaderColumns(): BasicColumn[] { | @@ -209,19 +197,19 @@ export function getMergeHeaderColumns(): BasicColumn[] { | ||
209 | { text: 'Male', value: 'male', children: [] }, | 197 | { text: 'Male', value: 'male', children: [] }, |
210 | { text: 'Female', value: 'female', children: [] }, | 198 | { text: 'Female', value: 'female', children: [] }, |
211 | ], | 199 | ], |
212 | - customRender: renderContent, | 200 | + customCell: cellContent, |
213 | }, | 201 | }, |
214 | { | 202 | { |
215 | title: '开始时间', | 203 | title: '开始时间', |
216 | dataIndex: 'beginTime', | 204 | dataIndex: 'beginTime', |
217 | width: 200, | 205 | width: 200, |
218 | - customRender: renderContent, | 206 | + customCell: cellContent, |
219 | }, | 207 | }, |
220 | { | 208 | { |
221 | title: '结束时间', | 209 | title: '结束时间', |
222 | dataIndex: 'endTime', | 210 | dataIndex: 'endTime', |
223 | width: 200, | 211 | width: 200, |
224 | - customRender: renderContent, | 212 | + customCell: cellContent, |
225 | }, | 213 | }, |
226 | ]; | 214 | ]; |
227 | } | 215 | } |