antd#TableColumnType TypeScript Examples
The following examples show how to use
antd#TableColumnType.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SchemaTable.tsx From datart with Apache License 2.0 | 5 votes |
SchemaTable = memo(
({
height,
width: propsWidth,
model,
hierarchy,
dataSource,
hasCategory,
getExtraHeaderActions,
onSchemaTypeChange,
...tableProps
}: SchemaTableProps) => {
const dataSourceWithKey = useMemo(
() => dataSource?.map(o => ({ ...o, [ROW_KEY]: uuidv4() })),
[dataSource],
);
const columnWidthMap = useMemo(
() => getColumnWidthMap(model, dataSource || []),
[model, dataSource],
);
const t = useI18NPrefix('view.schemaTable');
const tg = useI18NPrefix('global');
const {
columns,
tableWidth,
}: {
columns: TableColumnType<object>[];
tableWidth: number;
} = useMemo(() => {
let tableWidth = 0;
const columns = Object.entries(model).map(([name, column]) => {
const hierarchyColumn = getHierarchyColumn(name, hierarchy) || column;
const width = columnWidthMap[name];
tableWidth += width;
let icon;
switch (hierarchyColumn.type) {
case DataViewFieldType.NUMERIC:
icon = <NumberOutlined />;
break;
case DataViewFieldType.DATE:
icon = <CalendarOutlined />;
break;
default:
icon = <FieldStringOutlined />;
break;
}
const extraActions =
getExtraHeaderActions && getExtraHeaderActions(name, hierarchyColumn);
const title = (
<>
<span className="content">{name}</span>
<Dropdown
trigger={['click']}
overlay={
<Menu
selectedKeys={[
hierarchyColumn.type,
`category-${hierarchyColumn.category}`,
]}
className="datart-schema-table-header-menu"
onClick={onSchemaTypeChange(name, hierarchyColumn)}
>
{Object.values(DataViewFieldType).map(t => (
<Menu.Item key={t}>
{tg(`columnType.${t.toLowerCase()}`)}
</Menu.Item>
))}
{hasCategory && (
<>
<Menu.Divider />
<Menu.SubMenu
key="categories"
title={t('category')}
popupClassName="datart-schema-table-header-menu"
>
{Object.values(ColumnCategories).map(t => (
<Menu.Item key={`category-${t}`}>
{tg(`columnCategory.${t.toLowerCase()}`)}
</Menu.Item>
))}
</Menu.SubMenu>
</>
)}
</Menu>
}
>
<Tooltip title={hasCategory ? t('typeAndCategory') : t('type')}>
<ToolbarButton
size="small"
iconSize={FONT_SIZE_BASE}
className="suffix"
icon={icon}
/>
</Tooltip>
</Dropdown>
{extraActions}
</>
);
return {
title,
dataIndex: name,
width,
align:
column.type === DataViewFieldType.NUMERIC
? ('right' as const)
: ('left' as const),
};
});
return { columns, tableWidth };
}, [
model,
hierarchy,
columnWidthMap,
hasCategory,
getExtraHeaderActions,
onSchemaTypeChange,
t,
tg,
]);
return (
<VirtualTable
{...tableProps}
rowKey={ROW_KEY}
size="small"
components={{ header: { cell: TableHeader } }}
dataSource={dataSourceWithKey}
columns={columns}
scroll={{ x: tableWidth, y: height }}
width={propsWidth}
/>
);
},
)