/
MRT_TableFooterRow.tsx
90 lines (83 loc) · 2.53 KB
/
MRT_TableFooterRow.tsx
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import TableRow, { type TableRowProps } from '@mui/material/TableRow';
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
import {
type MRT_ColumnVirtualizer,
type MRT_Header,
type MRT_HeaderGroup,
type MRT_RowData,
type MRT_TableInstance,
type MRT_VirtualItem,
} from '../../types';
import { getMRTTheme } from '../../utils/style.utils';
import { parseFromValuesOrFunc } from '../../utils/utils';
interface Props<TData extends MRT_RowData> extends TableRowProps {
columnVirtualizer?: MRT_ColumnVirtualizer;
footerGroup: MRT_HeaderGroup<TData>;
table: MRT_TableInstance<TData>;
}
export const MRT_TableFooterRow = <TData extends MRT_RowData>({
columnVirtualizer,
footerGroup,
table,
...rest
}: Props<TData>) => {
const {
options: { layoutMode, muiTableFooterRowProps },
} = table;
const { virtualColumns, virtualPaddingLeft, virtualPaddingRight } =
columnVirtualizer ?? {};
// if no content in row, skip row
if (
!footerGroup.headers?.some(
(header) =>
(typeof header.column.columnDef.footer === 'string' &&
!!header.column.columnDef.footer) ||
header.column.columnDef.Footer,
)
)
return null;
const tableRowProps = {
...parseFromValuesOrFunc(muiTableFooterRowProps, {
footerGroup,
table,
}),
...rest,
};
return (
<TableRow
{...tableRowProps}
sx={(theme) => ({
backgroundColor: getMRTTheme(table, theme).baseBackgroundColor,
display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
position: 'relative',
width: '100%',
...(parseFromValuesOrFunc(tableRowProps?.sx, theme) as any),
})}
>
{virtualPaddingLeft ? (
<th style={{ display: 'flex', width: virtualPaddingLeft }} />
) : null}
{(virtualColumns ?? footerGroup.headers).map(
(footerOrVirtualFooter, staticColumnIndex) => {
let footer = footerOrVirtualFooter as MRT_Header<TData>;
if (columnVirtualizer) {
staticColumnIndex = (footerOrVirtualFooter as MRT_VirtualItem)
.index;
footer = footerGroup.headers[staticColumnIndex];
}
return footer ? (
<MRT_TableFooterCell
footer={footer}
key={footer.id}
staticColumnIndex={staticColumnIndex}
table={table}
/>
) : null;
},
)}
{virtualPaddingRight ? (
<th style={{ display: 'flex', width: virtualPaddingRight }} />
) : null}
</TableRow>
);
};