/
MRT_TableFooter.tsx
72 lines (67 loc) · 2.06 KB
/
MRT_TableFooter.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
import TableFooter, { type TableFooterProps } from '@mui/material/TableFooter';
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
import {
type MRT_ColumnVirtualizer,
type MRT_RowData,
type MRT_TableInstance,
} from '../../types';
import { parseFromValuesOrFunc } from '../../utils/utils';
interface Props<TData extends MRT_RowData> extends TableFooterProps {
columnVirtualizer?: MRT_ColumnVirtualizer;
table: MRT_TableInstance<TData>;
}
export const MRT_TableFooter = <TData extends MRT_RowData>({
columnVirtualizer,
table,
...rest
}: Props<TData>) => {
const {
getFooterGroups,
getState,
options: { enableStickyFooter, layoutMode, muiTableFooterProps },
refs: { tableFooterRef },
} = table;
const { isFullScreen } = getState();
const tableFooterProps = {
...parseFromValuesOrFunc(muiTableFooterProps, {
table,
}),
...rest,
};
const stickFooter =
(isFullScreen || enableStickyFooter) && enableStickyFooter !== false;
return (
<TableFooter
{...tableFooterProps}
ref={(ref: HTMLTableSectionElement) => {
tableFooterRef.current = ref;
if (tableFooterProps?.ref) {
// @ts-ignore
tableFooterProps.ref.current = ref;
}
}}
sx={(theme) => ({
bottom: stickFooter ? 0 : undefined,
display: layoutMode?.startsWith('grid') ? 'grid' : undefined,
opacity: stickFooter ? 0.97 : undefined,
outline: stickFooter
? theme.palette.mode === 'light'
? `1px solid ${theme.palette.grey[300]}`
: `1px solid ${theme.palette.grey[700]}`
: undefined,
position: stickFooter ? 'sticky' : 'relative',
zIndex: stickFooter ? 1 : undefined,
...(parseFromValuesOrFunc(tableFooterProps?.sx, theme) as any),
})}
>
{getFooterGroups().map((footerGroup) => (
<MRT_TableFooterRow
columnVirtualizer={columnVirtualizer}
footerGroup={footerGroup as any}
key={footerGroup.id}
table={table}
/>
))}
</TableFooter>
);
};