feat: table add transformCellText for custom render cell #2109
parent
dd83049170
commit
b55fa75b93
|
@ -26,6 +26,7 @@ const ConfigProvider = {
|
||||||
autoInsertSpaceInButton: PropTypes.bool,
|
autoInsertSpaceInButton: PropTypes.bool,
|
||||||
locale: PropTypes.object,
|
locale: PropTypes.object,
|
||||||
pageHeader: PropTypes.object,
|
pageHeader: PropTypes.object,
|
||||||
|
transformCellText: PropTypes.func,
|
||||||
},
|
},
|
||||||
provide() {
|
provide() {
|
||||||
const _self = this;
|
const _self = this;
|
||||||
|
@ -43,7 +44,14 @@ const ConfigProvider = {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
...getWatch(['prefixCls', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader']),
|
...getWatch([
|
||||||
|
'prefixCls',
|
||||||
|
'csp',
|
||||||
|
'autoInsertSpaceInButton',
|
||||||
|
'locale',
|
||||||
|
'pageHeader',
|
||||||
|
'transformCellText',
|
||||||
|
]),
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
renderEmptyComponent(h, name) {
|
renderEmptyComponent(h, name) {
|
||||||
|
|
|
@ -1164,6 +1164,7 @@ export default {
|
||||||
dropdownPrefixCls,
|
dropdownPrefixCls,
|
||||||
contextLocale,
|
contextLocale,
|
||||||
getPopupContainer: contextGetPopupContainer,
|
getPopupContainer: contextGetPopupContainer,
|
||||||
|
transformCellText,
|
||||||
}) {
|
}) {
|
||||||
const { showHeader, locale, getPopupContainer, ...restProps } = getOptionProps(this);
|
const { showHeader, locale, getPopupContainer, ...restProps } = getOptionProps(this);
|
||||||
const data = this.getCurrentPageData();
|
const data = this.getCurrentPageData();
|
||||||
|
@ -1220,6 +1221,7 @@ export default {
|
||||||
expandIconColumnIndex,
|
expandIconColumnIndex,
|
||||||
expandIconAsCell,
|
expandIconAsCell,
|
||||||
emptyText: mergedLocale.emptyText,
|
emptyText: mergedLocale.emptyText,
|
||||||
|
transformCellText,
|
||||||
},
|
},
|
||||||
on: getListeners(this),
|
on: getListeners(this),
|
||||||
class: classString,
|
class: classString,
|
||||||
|
@ -1230,10 +1232,18 @@ export default {
|
||||||
},
|
},
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const { prefixCls: customizePrefixCls, dropdownPrefixCls: customizeDropdownPrefixCls } = this;
|
const {
|
||||||
|
prefixCls: customizePrefixCls,
|
||||||
|
dropdownPrefixCls: customizeDropdownPrefixCls,
|
||||||
|
transformCellText: customizeTransformCellText,
|
||||||
|
} = this;
|
||||||
const data = this.getCurrentPageData();
|
const data = this.getCurrentPageData();
|
||||||
const { getPopupContainer: getContextPopupContainer } = this.configProvider;
|
const {
|
||||||
|
getPopupContainer: getContextPopupContainer,
|
||||||
|
transformCellText: tct,
|
||||||
|
} = this.configProvider;
|
||||||
const getPopupContainer = this.getPopupContainer || getContextPopupContainer;
|
const getPopupContainer = this.getPopupContainer || getContextPopupContainer;
|
||||||
|
const transformCellText = customizeTransformCellText || tct;
|
||||||
let loading = this.loading;
|
let loading = this.loading;
|
||||||
if (typeof loading === 'boolean') {
|
if (typeof loading === 'boolean') {
|
||||||
loading = {
|
loading = {
|
||||||
|
@ -1263,6 +1273,7 @@ export default {
|
||||||
dropdownPrefixCls,
|
dropdownPrefixCls,
|
||||||
contextLocale: locale,
|
contextLocale: locale,
|
||||||
getPopupContainer,
|
getPopupContainer,
|
||||||
|
transformCellText,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
|
|
|
@ -135,6 +135,7 @@ export const TableProps = {
|
||||||
tableLayout: PropTypes.string,
|
tableLayout: PropTypes.string,
|
||||||
getPopupContainer: PropTypes.func,
|
getPopupContainer: PropTypes.func,
|
||||||
expandIcon: PropTypes.func,
|
expandIcon: PropTypes.func,
|
||||||
|
transformCellText: PropTypes.func,
|
||||||
// className?: PropTypes.string,
|
// className?: PropTypes.string,
|
||||||
// style?: React.CSSProperties;
|
// style?: React.CSSProperties;
|
||||||
// children?: React.ReactNode;
|
// children?: React.ReactNode;
|
||||||
|
|
|
@ -67,6 +67,7 @@ export default {
|
||||||
expandRowByClick: PropTypes.bool,
|
expandRowByClick: PropTypes.bool,
|
||||||
expandIcon: PropTypes.func,
|
expandIcon: PropTypes.func,
|
||||||
tableLayout: PropTypes.string,
|
tableLayout: PropTypes.string,
|
||||||
|
transformCellText: PropTypes.func,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
data: [],
|
data: [],
|
||||||
|
|
|
@ -21,6 +21,9 @@ export default {
|
||||||
expandIcon: PropTypes.any,
|
expandIcon: PropTypes.any,
|
||||||
component: PropTypes.any,
|
component: PropTypes.any,
|
||||||
},
|
},
|
||||||
|
inject: {
|
||||||
|
table: { default: () => ({}) },
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
handleClick(e) {
|
handleClick(e) {
|
||||||
const {
|
const {
|
||||||
|
@ -45,6 +48,7 @@ export default {
|
||||||
component: BodyCell,
|
component: BodyCell,
|
||||||
} = this;
|
} = this;
|
||||||
const { dataIndex, customRender, className = '' } = column;
|
const { dataIndex, customRender, className = '' } = column;
|
||||||
|
const { transformCellText } = this.table;
|
||||||
// We should return undefined if no dataIndex is specified, but in order to
|
// 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.
|
// be compatible with object-path's behavior, we return the record object instead.
|
||||||
let text;
|
let text;
|
||||||
|
@ -87,6 +91,10 @@ export default {
|
||||||
text = null;
|
text = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (transformCellText) {
|
||||||
|
text = transformCellText({ text, column, record, index });
|
||||||
|
}
|
||||||
|
|
||||||
const indentText = expandIcon ? (
|
const indentText = expandIcon ? (
|
||||||
<span
|
<span
|
||||||
style={{ paddingLeft: `${indentSize * indent}px` }}
|
style={{ paddingLeft: `${indentSize * indent}px` }}
|
||||||
|
|
|
@ -13,4 +13,5 @@ export declare class ConfigProvider extends AntdComponent {
|
||||||
renderEmpty: Function;
|
renderEmpty: Function;
|
||||||
csp?: CSPConfig;
|
csp?: CSPConfig;
|
||||||
autoInsertSpaceInButton?: boolean;
|
autoInsertSpaceInButton?: boolean;
|
||||||
|
transformCellText?: Function;
|
||||||
}
|
}
|
||||||
|
|
|
@ -300,4 +300,5 @@ export declare class Table extends AntdComponent {
|
||||||
style: object;
|
style: object;
|
||||||
nativeOn: object;
|
nativeOn: object;
|
||||||
};
|
};
|
||||||
|
transformCellText: Function;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue