Table.tsx
1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//@ts-nocheck
import React from 'react';
import { Table as TableContainer, TableProps } from 'antd';
import { useWindowSize } from '@src/hooks';
import TableHeader from './TableHeader';
interface NewTableProps extends TableProps<any> {
title: string;
columns: Object[];
data: Object[];
}
export default function Table({
title,
columns,
data,
...rest
}: NewTableProps) {
const [width, height] = useWindowSize();
const size = width > 1000 ? 'middle' : 'small';
const cellHeight = size === 'small' ? 39 : 55;
const pageSize = Math.ceil((height * 2) / 3 / cellHeight);
const emptyRowNum = pageSize - (data.length % pageSize);
const emptyRow = columns.reduce(
(acc, curr) => ((acc[curr['dataIndex']] = '-'), acc),
{},
);
const body = [...data, ...Array(emptyRowNum || 0).fill(emptyRow)];
return (
<TableContainer
size={size}
title={() => <TableHeader title={title} />}
columns={columns}
dataSource={body}
pagination={{
responsive: true,
showLessItems: true,
pageSize,
}}
{...rest}
/>
);
}