Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import ResizeContext from '../context/ResizeContext';
import BodyRow from './BodyRow';
import useFlattenRecords from '../hooks/useFlattenRecords';
import HoverContext from '../context/HoverContext';
import PerfContext, { PerfRecord } from '../context/PerfContext';
import type { PerfRecord } from '../context/PerfContext';
import PerfContext from '../context/PerfContext';
import MeasureRow from './MeasureRow';

export interface BodyProps<RecordType> {
Expand Down
39 changes: 26 additions & 13 deletions src/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,23 @@ export type CellProps<RecordType extends DefaultRecordType> = Omit<
keyof HoverContextProps
>;

const getTitleFromCellRenderChildren = ({
ellipsis,
rowType,
children,
}: Pick<InternalCellProps<any>, 'ellipsis' | 'rowType' | 'children'>) => {
let title: string;
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
if (typeof children === 'string' || typeof children === 'number') {
title = children.toString();
} else if (React.isValidElement(children) && typeof children.props.children === 'string') {
title = children.props.children;
}
}
return title;
};

function Cell<RecordType extends DefaultRecordType>(
{
prefixCls,
Expand Down Expand Up @@ -132,7 +149,10 @@ function Cell<RecordType extends DefaultRecordType>(
return [children];
}

const value = getPathValue<object | React.ReactNode, RecordType>(record, dataIndex);
const value = getPathValue<Record<string, unknown> | React.ReactNode, RecordType>(
record,
dataIndex,
);

// Customize render node
let returnChildNode = value;
Expand Down Expand Up @@ -238,18 +258,11 @@ function Cell<RecordType extends DefaultRecordType>(
};

// ====================== Render ======================
let title: string;
const ellipsisConfig: CellEllipsisType = ellipsis === true ? { showTitle: true } : ellipsis;
if (ellipsisConfig && (ellipsisConfig.showTitle || rowType === 'header')) {
if (typeof mergedChildNode === 'string' || typeof mergedChildNode === 'number') {
title = mergedChildNode.toString();
} else if (
React.isValidElement(mergedChildNode) &&
typeof mergedChildNode.props.children === 'string'
) {
title = mergedChildNode.props.children;
}
}
const title = getTitleFromCellRenderChildren({
rowType,
ellipsis,
children: childNode,
});

const componentProps: React.TdHTMLAttributes<HTMLTableCellElement> & {
ref: React.Ref<any>;
Expand Down
10 changes: 9 additions & 1 deletion tests/FixedColumn.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ describe('Table.FixedColumn', () => {

const columns = [
{ title: 'title1', dataIndex: 'a', key: 'a', width: 100, fixed: 'left' },
{ title: 'title2', dataIndex: 'b', key: 'b', width: 100, fixed: 'left' },
{
title: 'title2',
dataIndex: 'b',
key: 'b',
width: 100,
fixed: 'left',
ellipsis: true,
render: () => <span>1111</span>,
},
{ title: 'title3', dataIndex: 'c', key: 'c' },
{ title: 'title4', dataIndex: 'b', key: 'd' },
{ title: 'title5', dataIndex: 'b', key: 'e' },
Expand Down
Loading