ant-design/components/table/util.ts
二货机器人 08f25f0c8f
chore: Update Table ts definition (#29084)
* chore: bump rc-table ver

* chore: Fix ts definition

* docs: fix doc
2021-01-28 01:21:58 +08:00

29 lines
807 B
TypeScript

/* eslint-disable import/prefer-default-export */
import { ColumnType, ColumnTitle, ColumnTitleProps, Key } from './interface';
export function getColumnKey<RecordType>(column: ColumnType<RecordType>, defaultKey: string): Key {
if ('key' in column && column.key !== undefined && column.key !== null) {
return column.key;
}
if (column.dataIndex) {
return (Array.isArray(column.dataIndex) ? column.dataIndex.join('.') : column.dataIndex) as Key;
}
return defaultKey;
}
export function getColumnPos(index: number, pos?: string) {
return pos ? `${pos}-${index}` : `${index}`;
}
export function renderColumnTitle<RecordType>(
title: ColumnTitle<RecordType>,
props: ColumnTitleProps<RecordType>,
) {
if (typeof title === 'function') {
return title(props);
}
return title;
}