Skip to content

Commit 41365f4

Browse files
tangjinzhouzhoudewei2526
authored andcommitted
feat: table add transformCellText for custom render cell vueComponent#2109
1 parent 5889f25 commit 41365f4

File tree

7 files changed

+34
-3
lines changed

7 files changed

+34
-3
lines changed

components/config-provider/index.jsx

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ConfigProvider = {
2626
autoInsertSpaceInButton: PropTypes.bool,
2727
locale: PropTypes.object,
2828
pageHeader: PropTypes.object,
29+
transformCellText: PropTypes.func,
2930
},
3031
provide() {
3132
const _self = this;
@@ -43,7 +44,14 @@ const ConfigProvider = {
4344
};
4445
},
4546
watch: {
46-
...getWatch(['prefixCls', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader']),
47+
...getWatch([
48+
'prefixCls',
49+
'csp',
50+
'autoInsertSpaceInButton',
51+
'locale',
52+
'pageHeader',
53+
'transformCellText',
54+
]),
4755
},
4856
methods: {
4957
renderEmptyComponent(h, name) {

components/table/Table.jsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -1164,6 +1164,7 @@ export default {
11641164
dropdownPrefixCls,
11651165
contextLocale,
11661166
getPopupContainer: contextGetPopupContainer,
1167+
transformCellText,
11671168
}) {
11681169
const { showHeader, locale, getPopupContainer, ...restProps } = getOptionProps(this);
11691170
const data = this.getCurrentPageData();
@@ -1220,6 +1221,7 @@ export default {
12201221
expandIconColumnIndex,
12211222
expandIconAsCell,
12221223
emptyText: mergedLocale.emptyText,
1224+
transformCellText,
12231225
},
12241226
on: getListeners(this),
12251227
class: classString,
@@ -1230,10 +1232,18 @@ export default {
12301232
},
12311233

12321234
render() {
1233-
const { prefixCls: customizePrefixCls, dropdownPrefixCls: customizeDropdownPrefixCls } = this;
1235+
const {
1236+
prefixCls: customizePrefixCls,
1237+
dropdownPrefixCls: customizeDropdownPrefixCls,
1238+
transformCellText: customizeTransformCellText,
1239+
} = this;
12341240
const data = this.getCurrentPageData();
1235-
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
1241+
const {
1242+
getPopupContainer: getContextPopupContainer,
1243+
transformCellText: tct,
1244+
} = this.configProvider;
12361245
const getPopupContainer = this.getPopupContainer || getContextPopupContainer;
1246+
const transformCellText = customizeTransformCellText || tct;
12371247
let loading = this.loading;
12381248
if (typeof loading === 'boolean') {
12391249
loading = {
@@ -1263,6 +1273,7 @@ export default {
12631273
dropdownPrefixCls,
12641274
contextLocale: locale,
12651275
getPopupContainer,
1276+
transformCellText,
12661277
})
12671278
}
12681279
/>

components/table/interface.js

+1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ export const TableProps = {
135135
tableLayout: PropTypes.string,
136136
getPopupContainer: PropTypes.func,
137137
expandIcon: PropTypes.func,
138+
transformCellText: PropTypes.func,
138139
// className?: PropTypes.string,
139140
// style?: React.CSSProperties;
140141
// children?: React.ReactNode;

components/vc-table/src/Table.jsx

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export default {
6767
expandRowByClick: PropTypes.bool,
6868
expandIcon: PropTypes.func,
6969
tableLayout: PropTypes.string,
70+
transformCellText: PropTypes.func,
7071
},
7172
{
7273
data: [],

components/vc-table/src/TableCell.jsx

+8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export default {
2121
expandIcon: PropTypes.any,
2222
component: PropTypes.any,
2323
},
24+
inject: {
25+
table: { default: () => ({}) },
26+
},
2427
methods: {
2528
handleClick(e) {
2629
const {
@@ -45,6 +48,7 @@ export default {
4548
component: BodyCell,
4649
} = this;
4750
const { dataIndex, customRender, className = '' } = column;
51+
const { transformCellText } = this.table;
4852
// We should return undefined if no dataIndex is specified, but in order to
4953
// be compatible with object-path's behavior, we return the record object instead.
5054
let text;
@@ -87,6 +91,10 @@ export default {
8791
text = null;
8892
}
8993

94+
if (transformCellText) {
95+
text = transformCellText({ text, column, record, index });
96+
}
97+
9098
const indentText = expandIcon ? (
9199
<span
92100
style={{ paddingLeft: `${indentSize * indent}px` }}

types/config-provider.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ export declare class ConfigProvider extends AntdComponent {
1313
renderEmpty: Function;
1414
csp?: CSPConfig;
1515
autoInsertSpaceInButton?: boolean;
16+
transformCellText?: Function;
1617
}

types/table/table.d.ts

+1
Original file line numberDiff line numberDiff line change
@@ -300,4 +300,5 @@ export declare class Table extends AntdComponent {
300300
style: object;
301301
nativeOn: object;
302302
};
303+
transformCellText: Function;
303304
}

0 commit comments

Comments
 (0)