Skip to content

Commit badd9f6

Browse files
betavsnovlan1tdesign-bot
authored
fix(table): handle custom class names for table columns (#4500)
* fix(table): handle custom class names for table columns * feat(table): 防止小程序编译报错 * chore: stash changelog [ci skip] --------- Co-authored-by: novlan1 <1576271227@qq.com> Co-authored-by: tdesign-bot <tdesign@tencent.com>
1 parent f150ec2 commit badd9f6

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
pr_number: 4500
3+
contributor: betavs
4+
---
5+
6+
- fix(Table): 修复列配置中的类名选项无效的问题 @betavs ([#4500](https://github.com/Tencent/tdesign-miniprogram/pull/4500))

packages/uniapp-components/table/table.vue

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,12 +295,27 @@ export default {
295295
return styles.join('; ');
296296
},
297297
298+
getCustomClassName(className = '') {
299+
const calcClassName = (name) => {
300+
if (typeof name === 'function') {
301+
return name() || '';
302+
}
303+
return name;
304+
};
305+
306+
if (Array.isArray(className)) {
307+
return className.map(calcClassName);
308+
}
309+
return [calcClassName(className)];
310+
},
311+
298312
getThClassName(col, colIndex) {
299313
const classes = [];
300314
if (col.colKey) classes.push(`${name}__th-${col.colKey}`);
301315
if (col.align && col.align !== 'left') classes.push(`${prefix}-align-${col.align}`);
302316
if (col.fixed === 'left') classes.push(`${name}__cell--fixed-left`);
303317
if (col.fixed === 'right') classes.push(`${name}__cell--fixed-right`);
318+
if (col.className) classes.push(...this.getCustomClassName(col.className));
304319
if (colIndex === this.lastFixedLeftIndex) classes.push(`${name}__cell--fixed-left-last`);
305320
if (colIndex === this.firstFixedRightIndex) classes.push(`${name}__cell--fixed-right-first`);
306321
return classes.join(' ');

0 commit comments

Comments
 (0)