material-react-table 0.3.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/MaterialReactTable.d.ts +46 -44
- package/dist/buttons/MRT_EditActionButtons.d.ts +7 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +4 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +7 -0
- package/dist/head/MRT_TableHeadCell.d.ts +1 -0
- package/dist/index.d.ts +2 -2
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/material-react-table.cjs.development.js +1459 -412
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +1474 -427
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +9 -0
- package/dist/{footer → toolbar}/MRT_TablePagination.d.ts +0 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +5 -0
- package/dist/toolbar/MRT_ToolbarButtons.d.ts +5 -0
- package/dist/toolbar/{MRT_Toolbar.d.ts → MRT_ToolbarTop.d.ts} +1 -1
- package/dist/useMaterialReactTable.d.ts +7 -1
- package/dist/utils/localization.d.ts +22 -14
- package/package.json +15 -13
- package/src/MaterialReactTable.tsx +117 -100
- package/src/body/MRT_TableBody.tsx +26 -27
- package/src/body/MRT_TableBodyCell.tsx +17 -6
- package/src/body/MRT_TableBodyRow.tsx +39 -23
- package/src/body/MRT_TableDetailPanel.tsx +38 -14
- package/src/buttons/MRT_EditActionButtons.tsx +51 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +9 -4
- package/src/buttons/MRT_ExpandButton.tsx +12 -6
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +12 -12
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +1 -1
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +65 -0
- package/src/footer/MRT_TableFooter.tsx +2 -17
- package/src/footer/MRT_TableFooterCell.tsx +18 -7
- package/src/footer/MRT_TableFooterRow.tsx +28 -14
- package/src/head/MRT_TableHead.tsx +6 -18
- package/src/head/MRT_TableHeadCell.tsx +37 -17
- package/src/head/MRT_TableHeadRow.tsx +42 -14
- package/src/index.tsx +2 -5
- package/src/inputs/MRT_DensePaddingSwitch.tsx +21 -0
- package/src/inputs/MRT_FilterTextField.tsx +5 -0
- package/src/inputs/MRT_SearchTextField.tsx +4 -4
- package/src/inputs/MRT_SelectAllCheckbox.tsx +11 -3
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +29 -24
- package/src/menus/MRT_RowActionMenu.tsx +52 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
- package/src/table/MRT_Table.tsx +13 -4
- package/src/table/MRT_TableContainer.tsx +9 -5
- package/src/table/MRT_TableSpacerCell.tsx +17 -1
- package/src/toolbar/MRT_TablePagination.tsx +37 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +58 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +27 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +81 -0
- package/src/useMaterialReactTable.tsx +36 -32
- package/src/utils/localization.ts +32 -16
- package/dist/utils/overrideWarnings.d.ts +0 -1
- package/src/footer/MRT_TablePagination.tsx +0 -42
- package/src/toolbar/MRT_Toolbar.tsx +0 -39
- package/src/utils/overrideWarnings.ts +0 -41
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
2
|
import { Collapse, TableCell, TableRow } from '@mui/material';
|
|
3
3
|
import { Row } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
@@ -11,25 +11,49 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row }) => {
|
|
|
11
11
|
const {
|
|
12
12
|
tableInstance,
|
|
13
13
|
renderDetailPanel,
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
muiTableDetailPanelProps,
|
|
15
|
+
muiTableBodyRowProps,
|
|
16
|
+
onDetailPanelClick,
|
|
16
17
|
} = useMaterialReactTable();
|
|
17
18
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
const mTableBodyRowProps =
|
|
20
|
+
muiTableBodyRowProps instanceof Function
|
|
21
|
+
? muiTableBodyRowProps(row)
|
|
22
|
+
: muiTableBodyRowProps;
|
|
23
|
+
|
|
24
|
+
const tableRowProps = {
|
|
25
|
+
...mTableBodyRowProps,
|
|
26
|
+
...row.getToggleRowExpandedProps(),
|
|
27
|
+
style: {
|
|
28
|
+
...row.getToggleRowExpandedProps().style,
|
|
29
|
+
...(mTableBodyRowProps?.style ?? {}),
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
const mTableDetailPanelProps =
|
|
34
|
+
muiTableDetailPanelProps instanceof Function
|
|
35
|
+
? muiTableDetailPanelProps(row)
|
|
36
|
+
: muiTableDetailPanelProps;
|
|
37
|
+
|
|
38
|
+
const tableCellProps = {
|
|
39
|
+
...mTableDetailPanelProps,
|
|
40
|
+
style: {
|
|
41
|
+
borderBottom: !row.isExpanded ? 'none' : undefined,
|
|
42
|
+
paddingBottom: row.isExpanded ? '1rem' : 0,
|
|
43
|
+
paddingTop: row.isExpanded ? '1rem' : 0,
|
|
44
|
+
transition: 'all 0.2s ease-in-out',
|
|
45
|
+
...(mTableDetailPanelProps?.style || {}),
|
|
46
|
+
},
|
|
47
|
+
};
|
|
21
48
|
|
|
22
49
|
return (
|
|
23
|
-
<TableRow {...
|
|
50
|
+
<TableRow hover {...tableRowProps}>
|
|
24
51
|
<TableCell
|
|
25
52
|
colSpan={tableInstance.visibleColumns.length + 10}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
transition: 'all 0.2s',
|
|
31
|
-
}}
|
|
32
|
-
{...tableDetailPanelProps}
|
|
53
|
+
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
54
|
+
onDetailPanelClick?.(event, row)
|
|
55
|
+
}
|
|
56
|
+
{...tableCellProps}
|
|
33
57
|
>
|
|
34
58
|
<Collapse in={row.isExpanded}>{renderDetailPanel?.(row)}</Collapse>
|
|
35
59
|
</TableCell>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, styled, Tooltip } from '@mui/material';
|
|
3
|
+
import SaveIcon from '@mui/icons-material/Save';
|
|
4
|
+
import CancelIcon from '@mui/icons-material/Cancel';
|
|
5
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
|
+
import { Row } from 'react-table';
|
|
7
|
+
|
|
8
|
+
const EditActionButtonWrappers = styled('div')({
|
|
9
|
+
display: 'flex',
|
|
10
|
+
gap: '0.75rem',
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
interface Props {
|
|
14
|
+
row: Row;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export const MRT_EditActionButtons: FC<Props> = ({ row }) => {
|
|
18
|
+
const { localization, setCurrentEditingRowId, onRowEditSubmit } =
|
|
19
|
+
useMaterialReactTable();
|
|
20
|
+
|
|
21
|
+
const handleCancel = () => {
|
|
22
|
+
setCurrentEditingRowId(null);
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const handleSave = async () => {
|
|
26
|
+
setCurrentEditingRowId(null);
|
|
27
|
+
await onRowEditSubmit?.(row);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<EditActionButtonWrappers>
|
|
32
|
+
<Tooltip arrow title={localization?.rowActionButtonCancel ?? ''}>
|
|
33
|
+
<IconButton
|
|
34
|
+
aria-label={localization?.rowActionButtonCancel}
|
|
35
|
+
onClick={handleCancel}
|
|
36
|
+
>
|
|
37
|
+
<CancelIcon />
|
|
38
|
+
</IconButton>
|
|
39
|
+
</Tooltip>
|
|
40
|
+
<Tooltip arrow title={localization?.rowActionButtonSave ?? ''}>
|
|
41
|
+
<IconButton
|
|
42
|
+
aria-label={localization?.rowActionButtonSave}
|
|
43
|
+
color="info"
|
|
44
|
+
onClick={handleSave}
|
|
45
|
+
>
|
|
46
|
+
<SaveIcon />
|
|
47
|
+
</IconButton>
|
|
48
|
+
</Tooltip>
|
|
49
|
+
</EditActionButtonWrappers>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
@@ -6,16 +6,21 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
6
6
|
interface Props {}
|
|
7
7
|
|
|
8
8
|
export const MRT_ExpandAllButton: FC<Props> = () => {
|
|
9
|
-
const {
|
|
10
|
-
|
|
9
|
+
const {
|
|
10
|
+
tableInstance,
|
|
11
|
+
localization,
|
|
12
|
+
anyRowsExpanded,
|
|
13
|
+
densePadding,
|
|
14
|
+
renderDetailPanel,
|
|
15
|
+
} = useMaterialReactTable();
|
|
11
16
|
|
|
12
17
|
return (
|
|
13
18
|
<TableCell
|
|
14
19
|
size="small"
|
|
15
20
|
{...tableInstance.getToggleAllRowsExpandedProps()}
|
|
16
21
|
style={{
|
|
17
|
-
padding: '0.5rem',
|
|
18
|
-
|
|
22
|
+
padding: densePadding ? '0' : '0.5rem 0.5rem',
|
|
23
|
+
transition: 'all 0.2s ease-in-out',
|
|
19
24
|
width: `${renderDetailPanel ? 2 : tableInstance.expandedDepth + 2}rem`,
|
|
20
25
|
}}
|
|
21
26
|
>
|
|
@@ -9,30 +9,36 @@ interface Props {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const MRT_ExpandButton: FC<Props> = ({ row }) => {
|
|
12
|
-
const { localization, tableInstance, renderDetailPanel } =
|
|
12
|
+
const { localization, tableInstance, densePadding, renderDetailPanel } =
|
|
13
13
|
useMaterialReactTable();
|
|
14
14
|
|
|
15
15
|
return (
|
|
16
16
|
<TableCell
|
|
17
17
|
size="small"
|
|
18
|
-
{...row.getToggleRowExpandedProps()}
|
|
19
18
|
style={{
|
|
20
|
-
padding: '0.
|
|
21
|
-
paddingRight: '0',
|
|
19
|
+
padding: densePadding ? '0' : '0.6rem 0',
|
|
22
20
|
paddingLeft: `${row.depth + 0.5}rem`,
|
|
21
|
+
transition: 'all 0.2s ease-in-out',
|
|
23
22
|
width: `${
|
|
24
23
|
renderDetailPanel ? 2 : tableInstance.expandedDepth - row.depth + 2
|
|
25
24
|
}rem`,
|
|
26
25
|
}}
|
|
27
26
|
>
|
|
28
27
|
<IconButton
|
|
28
|
+
disabled={!row.canExpand && !renderDetailPanel}
|
|
29
29
|
aria-label={localization?.expandButtonTitle}
|
|
30
30
|
title={localization?.expandButtonTitle}
|
|
31
|
+
{...row.getToggleRowExpandedProps()}
|
|
31
32
|
>
|
|
32
33
|
<ExpandMoreIcon
|
|
33
|
-
fontSize=
|
|
34
|
+
fontSize={row.canExpand || renderDetailPanel ? 'medium' : 'small'}
|
|
34
35
|
style={{
|
|
35
|
-
transform:
|
|
36
|
+
transform:
|
|
37
|
+
!row.canExpand && !renderDetailPanel
|
|
38
|
+
? 'rotate(-90deg)'
|
|
39
|
+
: row.isExpanded
|
|
40
|
+
? 'rotate(-180deg)'
|
|
41
|
+
: 'rotate(0)',
|
|
36
42
|
transition: 'transform 0.2s',
|
|
37
43
|
}}
|
|
38
44
|
/>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
-
import { IconButton, Menu,
|
|
2
|
+
import { IconButton, Menu, Tooltip } from '@mui/material';
|
|
3
3
|
import ViewColumnIcon from '@mui/icons-material/ViewColumn';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
import { MRT_ShowHideColumnsMenu } from '../menus/MRT_ShowHideColumnsMenu';
|
|
@@ -16,16 +16,16 @@ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
return (
|
|
19
|
-
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</
|
|
19
|
+
<>
|
|
20
|
+
<Tooltip arrow title={localization?.showHideColumnsButtonTitle ?? ''}>
|
|
21
|
+
<IconButton
|
|
22
|
+
aria-label={localization?.showHideColumnsButtonTitle}
|
|
23
|
+
onClick={handleClick}
|
|
24
|
+
size="small"
|
|
25
|
+
>
|
|
26
|
+
<ViewColumnIcon />
|
|
27
|
+
</IconButton>
|
|
28
|
+
</Tooltip>
|
|
29
29
|
<Menu
|
|
30
30
|
anchorEl={anchorEl}
|
|
31
31
|
open={!!anchorEl}
|
|
@@ -38,6 +38,6 @@ export const MRT_ShowHideColumnsButton: FC<Props> = () => {
|
|
|
38
38
|
/>
|
|
39
39
|
))}
|
|
40
40
|
</Menu>
|
|
41
|
-
|
|
41
|
+
</>
|
|
42
42
|
);
|
|
43
43
|
};
|
|
@@ -6,7 +6,7 @@ import { MRT_ColumnActionMenu } from '../menus/MRT_ColumnActionMenu';
|
|
|
6
6
|
import { HeaderGroup } from 'react-table';
|
|
7
7
|
|
|
8
8
|
const IconButton = styled(MuiIconButton)({
|
|
9
|
-
opacity: 0.
|
|
9
|
+
opacity: 0.5,
|
|
10
10
|
transition: 'opacity 0.2s',
|
|
11
11
|
marginRight: '2px',
|
|
12
12
|
height: '2rem',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import FilterListIcon from '@mui/icons-material/FilterList';
|
|
5
|
+
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
|
6
|
+
|
|
7
|
+
type Props = {};
|
|
8
|
+
|
|
9
|
+
export const MRT_ToggleFiltersButton: FC<Props> = () => {
|
|
10
|
+
const { localization, setShowFilters, showFilters } = useMaterialReactTable();
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Tooltip arrow title={localization?.toggleFilterButtonTitle ?? ''}>
|
|
14
|
+
<IconButton
|
|
15
|
+
aria-label={localization?.toggleFilterButtonTitle}
|
|
16
|
+
onClick={() => setShowFilters(!showFilters)}
|
|
17
|
+
size="small"
|
|
18
|
+
>
|
|
19
|
+
{showFilters ? <FilterListOffIcon /> : <FilterListIcon />}
|
|
20
|
+
</IconButton>
|
|
21
|
+
</Tooltip>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import React, { FC, MouseEvent, useState } from 'react';
|
|
2
|
+
import { IconButton as MuiIconButton, styled } from '@mui/material';
|
|
3
|
+
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
4
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
import { Row } from 'react-table';
|
|
6
|
+
import { MRT_RowActionMenu } from '../menus/MRT_RowActionMenu';
|
|
7
|
+
import { MRT_EditActionButtons } from './MRT_EditActionButtons';
|
|
8
|
+
|
|
9
|
+
const IconButton = styled(MuiIconButton)({
|
|
10
|
+
opacity: 0.5,
|
|
11
|
+
transition: 'opacity 0.2s',
|
|
12
|
+
marginRight: '2px',
|
|
13
|
+
height: '2rem',
|
|
14
|
+
width: '2rem',
|
|
15
|
+
'&:hover': {
|
|
16
|
+
opacity: 1,
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
interface Props {
|
|
21
|
+
row: Row;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const MRT_ToggleRowActionMenuButton: FC<Props> = ({ row }) => {
|
|
25
|
+
const {
|
|
26
|
+
localization,
|
|
27
|
+
currentEditingRowId,
|
|
28
|
+
renderRowActions,
|
|
29
|
+
tableInstance,
|
|
30
|
+
} = useMaterialReactTable();
|
|
31
|
+
|
|
32
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
33
|
+
|
|
34
|
+
const handleOpenRowActionMenu = (event: MouseEvent<HTMLElement>) => {
|
|
35
|
+
event.stopPropagation();
|
|
36
|
+
event.preventDefault();
|
|
37
|
+
setAnchorEl(event.currentTarget);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
if (renderRowActions) {
|
|
41
|
+
return <>{renderRowActions(row, tableInstance)}</>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (row.id === currentEditingRowId) {
|
|
45
|
+
return <MRT_EditActionButtons row={row} />;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return (
|
|
49
|
+
<>
|
|
50
|
+
<IconButton
|
|
51
|
+
aria-label={localization?.rowActionMenuButtonTitle}
|
|
52
|
+
title={localization?.rowActionMenuButtonTitle}
|
|
53
|
+
onClick={handleOpenRowActionMenu}
|
|
54
|
+
size="small"
|
|
55
|
+
>
|
|
56
|
+
<MoreHorizIcon />
|
|
57
|
+
</IconButton>
|
|
58
|
+
<MRT_RowActionMenu
|
|
59
|
+
anchorEl={anchorEl}
|
|
60
|
+
row={row}
|
|
61
|
+
setAnchorEl={setAnchorEl}
|
|
62
|
+
/>
|
|
63
|
+
</>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
@@ -2,35 +2,20 @@ import React, { FC } from 'react';
|
|
|
2
2
|
import { TableFooter } from '@mui/material';
|
|
3
3
|
import { MRT_TableFooterRow } from './MRT_TableFooterRow';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
-
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
6
5
|
|
|
7
6
|
interface Props {}
|
|
8
7
|
|
|
9
8
|
export const MRT_TableFooter: FC<Props> = () => {
|
|
10
|
-
const {
|
|
11
|
-
overrideTableFooterComponent,
|
|
12
|
-
enablePagination,
|
|
13
|
-
positionPagination,
|
|
14
|
-
tableFooterProps,
|
|
15
|
-
tableInstance,
|
|
16
|
-
} = useMaterialReactTable();
|
|
17
|
-
|
|
18
|
-
if (overrideTableFooterComponent) {
|
|
19
|
-
return <>{overrideTableFooterComponent(tableInstance)}</>;
|
|
20
|
-
}
|
|
9
|
+
const { muiTableFooterProps, tableInstance } = useMaterialReactTable();
|
|
21
10
|
|
|
22
11
|
return (
|
|
23
|
-
<TableFooter {...
|
|
12
|
+
<TableFooter {...muiTableFooterProps}>
|
|
24
13
|
{tableInstance.footerGroups.map((footerGroup, index) => (
|
|
25
14
|
<MRT_TableFooterRow
|
|
26
15
|
key={`${index}-${footerGroup.id}`}
|
|
27
16
|
footerGroup={footerGroup}
|
|
28
17
|
/>
|
|
29
18
|
))}
|
|
30
|
-
{enablePagination &&
|
|
31
|
-
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
32
|
-
<MRT_TablePagination />
|
|
33
|
-
)}
|
|
34
19
|
</TableFooter>
|
|
35
20
|
);
|
|
36
21
|
};
|
|
@@ -12,20 +12,31 @@ interface Props {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
|
|
15
|
-
const {
|
|
16
|
-
useMaterialReactTable();
|
|
17
|
-
|
|
18
|
-
if (overrideTableFooterCellComponent) {
|
|
19
|
-
return <>{overrideTableFooterCellComponent(column, tableInstance)}</>;
|
|
20
|
-
}
|
|
15
|
+
const { muiTableFooterCellProps, densePadding } = useMaterialReactTable();
|
|
21
16
|
|
|
22
17
|
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
23
18
|
|
|
19
|
+
const mTableFooterCellProps =
|
|
20
|
+
muiTableFooterCellProps instanceof Function
|
|
21
|
+
? muiTableFooterCellProps(column)
|
|
22
|
+
: muiTableFooterCellProps;
|
|
23
|
+
|
|
24
|
+
const tableCellProps = {
|
|
25
|
+
...mTableFooterCellProps,
|
|
26
|
+
...column.getFooterProps(),
|
|
27
|
+
style: {
|
|
28
|
+
padding: densePadding ? '0.5rem' : '1rem',
|
|
29
|
+
transition: 'all 0.2s ease-in-out',
|
|
30
|
+
...column.getFooterProps().style,
|
|
31
|
+
...(mTableFooterCellProps?.style ?? {}),
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
|
|
24
35
|
return (
|
|
25
36
|
<TableCell
|
|
26
37
|
align={isParentHeader ? 'center' : 'left'}
|
|
27
38
|
variant="head"
|
|
28
|
-
{...
|
|
39
|
+
{...tableCellProps}
|
|
29
40
|
>
|
|
30
41
|
{column.render('Footer')}
|
|
31
42
|
</TableCell>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TableRow } from '@mui/material';
|
|
3
3
|
import { HeaderGroup } from 'react-table';
|
|
4
4
|
import { MRT_TableFooterCell } from './MRT_TableFooterCell';
|
|
5
5
|
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
@@ -14,35 +14,49 @@ export const MRT_TableFooterRow: FC<Props> = ({ footerGroup }) => {
|
|
|
14
14
|
renderDetailPanel,
|
|
15
15
|
columns,
|
|
16
16
|
anyRowsCanExpand,
|
|
17
|
-
enableColumnHiding,
|
|
18
17
|
enableSelection,
|
|
18
|
+
enableRowActions,
|
|
19
|
+
positionActionsColumn,
|
|
19
20
|
tableInstance,
|
|
20
|
-
|
|
21
|
+
muiTableFooterRowProps,
|
|
21
22
|
} = useMaterialReactTable();
|
|
22
23
|
|
|
23
24
|
//if no content in row, skip row
|
|
24
25
|
if (!columns?.some((c) => c.Footer)) return null;
|
|
25
26
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const mTableFooterRowProps =
|
|
28
|
+
muiTableFooterRowProps instanceof Function
|
|
29
|
+
? muiTableFooterRowProps(footerGroup)
|
|
30
|
+
: muiTableFooterRowProps;
|
|
31
|
+
|
|
32
|
+
const tableRowProps = {
|
|
33
|
+
...mTableFooterRowProps,
|
|
34
|
+
...footerGroup.getFooterGroupProps(),
|
|
35
|
+
style: {
|
|
36
|
+
...footerGroup.getFooterGroupProps().style,
|
|
37
|
+
...(mTableFooterRowProps?.style ?? {}),
|
|
38
|
+
},
|
|
39
|
+
};
|
|
29
40
|
|
|
30
41
|
return (
|
|
31
|
-
<TableRow {...
|
|
42
|
+
<TableRow {...tableRowProps}>
|
|
43
|
+
{enableRowActions && positionActionsColumn === 'first' && (
|
|
44
|
+
<MRT_TableSpacerCell />
|
|
45
|
+
)}
|
|
32
46
|
{(anyRowsCanExpand || renderDetailPanel) && (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}rem`,
|
|
38
|
-
}}
|
|
47
|
+
<MRT_TableSpacerCell
|
|
48
|
+
width={`${
|
|
49
|
+
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
50
|
+
}rem`}
|
|
39
51
|
/>
|
|
40
52
|
)}
|
|
41
53
|
{enableSelection && <MRT_TableSpacerCell width="1rem" />}
|
|
42
54
|
{footerGroup.headers.map((column, index) => (
|
|
43
55
|
<MRT_TableFooterCell key={`${index}-${column.id}`} column={column} />
|
|
44
56
|
))}
|
|
45
|
-
{
|
|
57
|
+
{enableRowActions && positionActionsColumn === 'last' && (
|
|
58
|
+
<MRT_TableSpacerCell />
|
|
59
|
+
)}
|
|
46
60
|
</TableRow>
|
|
47
61
|
);
|
|
48
62
|
};
|
|
@@ -1,32 +1,20 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { TableHead } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadRow } from './MRT_TableHeadRow';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
-
import { MRT_TablePagination } from '../footer/MRT_TablePagination';
|
|
6
5
|
|
|
7
6
|
interface Props {}
|
|
8
7
|
|
|
9
8
|
export const MRT_TableHead: FC<Props> = () => {
|
|
10
|
-
const {
|
|
11
|
-
overrideTableHeadComponent,
|
|
12
|
-
tableInstance,
|
|
13
|
-
tableHeadProps,
|
|
14
|
-
enablePagination,
|
|
15
|
-
isFetching,
|
|
16
|
-
positionPagination,
|
|
17
|
-
} = useMaterialReactTable();
|
|
9
|
+
const { tableInstance, muiTableHeadProps } = useMaterialReactTable();
|
|
18
10
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
11
|
+
const tableHeadProps =
|
|
12
|
+
muiTableHeadProps instanceof Function
|
|
13
|
+
? muiTableHeadProps(tableInstance)
|
|
14
|
+
: muiTableHeadProps;
|
|
22
15
|
|
|
23
16
|
return (
|
|
24
17
|
<TableHead {...tableHeadProps}>
|
|
25
|
-
{isFetching && <LinearProgress />}
|
|
26
|
-
{enablePagination &&
|
|
27
|
-
['top', 'both'].includes(positionPagination ?? '') && (
|
|
28
|
-
<MRT_TablePagination />
|
|
29
|
-
)}
|
|
30
18
|
{tableInstance.headerGroups.map((headerGroup, index) => (
|
|
31
19
|
<MRT_TableHeadRow
|
|
32
20
|
key={`${index}-${headerGroup.id}`}
|
|
@@ -11,8 +11,9 @@ import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
|
11
11
|
import { MRT_FilterTextfield } from '../inputs/MRT_FilterTextField';
|
|
12
12
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
13
13
|
|
|
14
|
-
const
|
|
14
|
+
export const StyledTableHeadCell = styled(MuiTableCell)({
|
|
15
15
|
fontWeight: 'bold',
|
|
16
|
+
verticalAlign: 'text-top',
|
|
16
17
|
});
|
|
17
18
|
|
|
18
19
|
const TableCellContents = styled('div')({
|
|
@@ -28,6 +29,7 @@ const TableCellText = styled('div')({
|
|
|
28
29
|
const CellFlexItem = styled('span')({
|
|
29
30
|
display: 'flex',
|
|
30
31
|
flexWrap: 'nowrap',
|
|
32
|
+
alignItems: 'center',
|
|
31
33
|
});
|
|
32
34
|
|
|
33
35
|
const Divider = styled(MuiDivider)({
|
|
@@ -42,25 +44,36 @@ interface Props {
|
|
|
42
44
|
|
|
43
45
|
export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
44
46
|
const {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
+
densePadding,
|
|
48
|
+
disableColumnActions,
|
|
49
|
+
disableFilters,
|
|
47
50
|
enableColumnResizing,
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
localization,
|
|
52
|
+
muiTableHeadCellProps,
|
|
53
|
+
showFilters,
|
|
50
54
|
tableInstance,
|
|
51
55
|
} = useMaterialReactTable();
|
|
52
56
|
|
|
53
|
-
if (overrideTableHeadCellComponent) {
|
|
54
|
-
return <>{overrideTableHeadCellComponent(column, tableInstance)}</>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
57
|
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
58
58
|
|
|
59
|
+
const mTableHeadCellProps =
|
|
60
|
+
muiTableHeadCellProps instanceof Function
|
|
61
|
+
? muiTableHeadCellProps(column)
|
|
62
|
+
: muiTableHeadCellProps;
|
|
63
|
+
|
|
64
|
+
const tableCellProps = {
|
|
65
|
+
...mTableHeadCellProps,
|
|
66
|
+
...column.getHeaderProps(),
|
|
67
|
+
style: {
|
|
68
|
+
padding: densePadding ? '0.5rem' : '1rem',
|
|
69
|
+
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
70
|
+
...column.getHeaderProps().style,
|
|
71
|
+
...(mTableHeadCellProps?.style ?? {}),
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
59
75
|
return (
|
|
60
|
-
<
|
|
61
|
-
align={isParentHeader ? 'center' : 'left'}
|
|
62
|
-
{...column.getHeaderProps()}
|
|
63
|
-
>
|
|
76
|
+
<StyledTableHeadCell align={isParentHeader ? 'center' : 'left'} {...tableCellProps}>
|
|
64
77
|
<TableCellContents>
|
|
65
78
|
<TableCellText
|
|
66
79
|
style={{ justifyContent: isParentHeader ? 'center' : undefined }}
|
|
@@ -69,6 +82,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
69
82
|
{column.render('Header')}
|
|
70
83
|
{!isParentHeader && column.canSort && (
|
|
71
84
|
<TableSortLabel
|
|
85
|
+
aria-label={
|
|
86
|
+
column.isSorted
|
|
87
|
+
? column.sortDescFirst
|
|
88
|
+
? localization?.columnActionMenuItemClearSort
|
|
89
|
+
: localization?.columnActionMenuItemSortDesc
|
|
90
|
+
: localization?.columnActionMenuItemSortAsc
|
|
91
|
+
}
|
|
72
92
|
active={column.isSorted}
|
|
73
93
|
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
74
94
|
style={{ margin: 0 }}
|
|
@@ -76,7 +96,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
76
96
|
)}
|
|
77
97
|
</CellFlexItem>
|
|
78
98
|
<CellFlexItem>
|
|
79
|
-
{
|
|
99
|
+
{!disableColumnActions && !isParentHeader && (
|
|
80
100
|
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
81
101
|
)}
|
|
82
102
|
{enableColumnResizing && !isParentHeader && (
|
|
@@ -89,12 +109,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
89
109
|
)}
|
|
90
110
|
</CellFlexItem>
|
|
91
111
|
</TableCellText>
|
|
92
|
-
{
|
|
93
|
-
<Collapse in={
|
|
112
|
+
{!disableFilters && column.canFilter && (
|
|
113
|
+
<Collapse in={showFilters}>
|
|
94
114
|
<MRT_FilterTextfield column={column} />
|
|
95
115
|
</Collapse>
|
|
96
116
|
)}
|
|
97
117
|
</TableCellContents>
|
|
98
|
-
</
|
|
118
|
+
</StyledTableHeadCell>
|
|
99
119
|
);
|
|
100
120
|
};
|