diff --git a/components/config-provider/index.jsx b/components/config-provider/index.jsx index 1083f40f9..5a591989d 100644 --- a/components/config-provider/index.jsx +++ b/components/config-provider/index.jsx @@ -26,6 +26,7 @@ const ConfigProvider = { autoInsertSpaceInButton: PropTypes.bool, locale: PropTypes.object, pageHeader: PropTypes.object, + transformCellText: PropTypes.func, }, provide() { const _self = this; @@ -43,7 +44,14 @@ const ConfigProvider = { }; }, watch: { - ...getWatch(['prefixCls', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader']), + ...getWatch([ + 'prefixCls', + 'csp', + 'autoInsertSpaceInButton', + 'locale', + 'pageHeader', + 'transformCellText', + ]), }, methods: { renderEmptyComponent(h, name) { diff --git a/components/table/Table.jsx b/components/table/Table.jsx index 5fed3809a..21137ee0f 100755 --- a/components/table/Table.jsx +++ b/components/table/Table.jsx @@ -1164,6 +1164,7 @@ export default { dropdownPrefixCls, contextLocale, getPopupContainer: contextGetPopupContainer, + transformCellText, }) { const { showHeader, locale, getPopupContainer, ...restProps } = getOptionProps(this); const data = this.getCurrentPageData(); @@ -1220,6 +1221,7 @@ export default { expandIconColumnIndex, expandIconAsCell, emptyText: mergedLocale.emptyText, + transformCellText, }, on: getListeners(this), class: classString, @@ -1230,10 +1232,18 @@ export default { }, render() { - const { prefixCls: customizePrefixCls, dropdownPrefixCls: customizeDropdownPrefixCls } = this; + const { + prefixCls: customizePrefixCls, + dropdownPrefixCls: customizeDropdownPrefixCls, + transformCellText: customizeTransformCellText, + } = this; const data = this.getCurrentPageData(); - const { getPopupContainer: getContextPopupContainer } = this.configProvider; + const { + getPopupContainer: getContextPopupContainer, + transformCellText: tct, + } = this.configProvider; const getPopupContainer = this.getPopupContainer || getContextPopupContainer; + const transformCellText = customizeTransformCellText || tct; let loading = this.loading; if (typeof loading === 'boolean') { loading = { @@ -1263,6 +1273,7 @@ export default { dropdownPrefixCls, contextLocale: locale, getPopupContainer, + transformCellText, }) } /> diff --git a/components/table/interface.js b/components/table/interface.js index b8c3e0ea8..dc26d9fb4 100644 --- a/components/table/interface.js +++ b/components/table/interface.js @@ -135,6 +135,7 @@ export const TableProps = { tableLayout: PropTypes.string, getPopupContainer: PropTypes.func, expandIcon: PropTypes.func, + transformCellText: PropTypes.func, // className?: PropTypes.string, // style?: React.CSSProperties; // children?: React.ReactNode; diff --git a/components/vc-table/src/Table.jsx b/components/vc-table/src/Table.jsx index df0eba052..90dce9b5c 100644 --- a/components/vc-table/src/Table.jsx +++ b/components/vc-table/src/Table.jsx @@ -67,6 +67,7 @@ export default { expandRowByClick: PropTypes.bool, expandIcon: PropTypes.func, tableLayout: PropTypes.string, + transformCellText: PropTypes.func, }, { data: [], diff --git a/components/vc-table/src/TableCell.jsx b/components/vc-table/src/TableCell.jsx index 6dc5e5b47..b82dcf6ec 100644 --- a/components/vc-table/src/TableCell.jsx +++ b/components/vc-table/src/TableCell.jsx @@ -21,6 +21,9 @@ export default { expandIcon: PropTypes.any, component: PropTypes.any, }, + inject: { + table: { default: () => ({}) }, + }, methods: { handleClick(e) { const { @@ -45,6 +48,7 @@ export default { component: BodyCell, } = this; const { dataIndex, customRender, className = '' } = column; + const { transformCellText } = this.table; // We should return undefined if no dataIndex is specified, but in order to // be compatible with object-path's behavior, we return the record object instead. let text; @@ -87,6 +91,10 @@ export default { text = null; } + if (transformCellText) { + text = transformCellText({ text, column, record, index }); + } + const indentText = expandIcon ? (