material-react-table 0.3.0 → 0.3.4
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/README.md +32 -162
- package/dist/MaterialReactTable.d.ts +52 -45
- package/dist/body/MRT_TableBodyRow.d.ts +16 -1
- 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/buttons/MRT_ToggleSearchButton.d.ts +4 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -0
- package/dist/index.d.ts +2 -2
- package/dist/inputs/MRT_DensePaddingSwitch.d.ts +5 -0
- package/dist/inputs/MRT_EditCellTextField.d.ts +7 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +1732 -466
- 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 +1743 -477
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +2 -2
- package/dist/menus/MRT_RowActionMenu.d.ts +10 -0
- package/dist/table/MRT_TableButtonCell.d.ts +3 -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 +10 -2
- package/dist/utils/localization.d.ts +25 -14
- package/dist/utils/useMRTCalcs.d.ts +1 -1
- package/package.json +26 -21
- package/src/@types/faker.d.ts +4 -0
- package/src/@types/react-table-config.d.ts +131 -0
- package/src/MaterialReactTable.tsx +92 -101
- package/src/body/MRT_TableBody.tsx +17 -40
- package/src/body/MRT_TableBodyCell.tsx +36 -11
- package/src/body/MRT_TableBodyRow.tsx +35 -26
- package/src/body/MRT_TableDetailPanel.tsx +41 -15
- package/src/buttons/MRT_EditActionButtons.tsx +49 -0
- package/src/buttons/MRT_ExpandAllButton.tsx +15 -19
- package/src/buttons/MRT_ExpandButton.tsx +23 -21
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +14 -21
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -9
- package/src/buttons/MRT_ToggleFiltersButton.tsx +23 -0
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +83 -0
- package/src/buttons/MRT_ToggleSearchButton.tsx +29 -0
- package/src/footer/MRT_TableFooter.tsx +4 -22
- package/src/footer/MRT_TableFooterCell.tsx +35 -10
- package/src/footer/MRT_TableFooterRow.tsx +24 -16
- package/src/head/MRT_TableHead.tsx +6 -23
- package/src/head/MRT_TableHeadCell.tsx +65 -28
- package/src/head/MRT_TableHeadRow.tsx +44 -17
- package/src/index.tsx +2 -5
- package/src/inputs/MRT_DensePaddingSwitch.tsx +23 -0
- package/src/inputs/MRT_EditCellTextField.tsx +64 -0
- package/src/inputs/MRT_FilterTextField.tsx +42 -15
- package/src/inputs/MRT_SearchTextField.tsx +40 -43
- package/src/inputs/MRT_SelectAllCheckbox.tsx +9 -6
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +69 -48
- package/src/menus/MRT_RowActionMenu.tsx +33 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +2 -2
- package/src/table/MRT_Table.tsx +13 -5
- package/src/table/MRT_TableButtonCell.tsx +9 -0
- package/src/table/MRT_TableContainer.tsx +32 -5
- package/src/table/MRT_TableSpacerCell.tsx +15 -1
- package/src/toolbar/MRT_TablePagination.tsx +34 -0
- package/src/toolbar/MRT_ToolbarBottom.tsx +41 -0
- package/src/toolbar/MRT_ToolbarButtons.tsx +29 -0
- package/src/toolbar/MRT_ToolbarTop.tsx +59 -0
- package/src/useMaterialReactTable.tsx +40 -44
- package/src/utils/localization.ts +42 -20
- package/src/utils/useMRTCalcs.tsx +1 -3
- 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
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
import SearchIcon from '@mui/icons-material/Search';
|
|
5
|
+
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
6
|
+
|
|
7
|
+
type Props = {};
|
|
8
|
+
|
|
9
|
+
export const MRT_ToggleSearchButton: FC<Props> = () => {
|
|
10
|
+
const { localization, setShowSearch, showSearch, muiSearchTextFieldProps } =
|
|
11
|
+
useMaterialReactTable();
|
|
12
|
+
|
|
13
|
+
const handleToggleSearch = () => {
|
|
14
|
+
setShowSearch(!showSearch);
|
|
15
|
+
setTimeout(
|
|
16
|
+
() =>
|
|
17
|
+
document.getElementById(muiSearchTextFieldProps?.id ?? `global-search-text-field`)?.focus(),
|
|
18
|
+
200,
|
|
19
|
+
);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Tooltip arrow title={localization?.toggleSearchButtonTitle ?? ''}>
|
|
24
|
+
<IconButton size="small" onClick={handleToggleSearch}>
|
|
25
|
+
{showSearch ? <SearchOffIcon /> : <SearchIcon />}
|
|
26
|
+
</IconButton>
|
|
27
|
+
</Tooltip>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
@@ -2,35 +2,17 @@ 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 {...
|
|
24
|
-
{tableInstance.footerGroups.map((footerGroup
|
|
25
|
-
<MRT_TableFooterRow
|
|
26
|
-
key={`${index}-${footerGroup.id}`}
|
|
27
|
-
footerGroup={footerGroup}
|
|
28
|
-
/>
|
|
12
|
+
<TableFooter {...muiTableFooterProps}>
|
|
13
|
+
{tableInstance.footerGroups.map((footerGroup) => (
|
|
14
|
+
<MRT_TableFooterRow key={footerGroup.getFooterGroupProps().key} footerGroup={footerGroup} />
|
|
29
15
|
))}
|
|
30
|
-
{enablePagination &&
|
|
31
|
-
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
32
|
-
<MRT_TablePagination />
|
|
33
|
-
)}
|
|
34
16
|
</TableFooter>
|
|
35
17
|
);
|
|
36
18
|
};
|
|
@@ -3,29 +3,54 @@ import { styled, TableCell as MuiTableCell } from '@mui/material';
|
|
|
3
3
|
import { HeaderGroup } from 'react-table';
|
|
4
4
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
5
|
|
|
6
|
-
const TableCell = styled(MuiTableCell
|
|
7
|
-
|
|
8
|
-
});
|
|
6
|
+
const TableCell = styled(MuiTableCell, {
|
|
7
|
+
shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
8
|
+
})<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
|
|
9
|
+
({ densePadding, enableColumnResizing }) => ({
|
|
10
|
+
fontWeight: 'bold',
|
|
11
|
+
verticalAlign: 'text-top',
|
|
12
|
+
padding: densePadding ? '0.5rem' : '1rem',
|
|
13
|
+
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
9
16
|
|
|
10
17
|
interface Props {
|
|
11
18
|
column: HeaderGroup;
|
|
12
19
|
}
|
|
13
20
|
|
|
14
21
|
export const MRT_TableFooterCell: FC<Props> = ({ column }) => {
|
|
15
|
-
const {
|
|
16
|
-
useMaterialReactTable();
|
|
17
|
-
|
|
18
|
-
if (overrideTableFooterCellComponent) {
|
|
19
|
-
return <>{overrideTableFooterCellComponent(column, tableInstance)}</>;
|
|
20
|
-
}
|
|
22
|
+
const { muiTableFooterCellProps, densePadding, enableColumnResizing } = useMaterialReactTable();
|
|
21
23
|
|
|
22
24
|
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
23
25
|
|
|
26
|
+
const mTableFooterCellProps =
|
|
27
|
+
muiTableFooterCellProps instanceof Function
|
|
28
|
+
? muiTableFooterCellProps(column)
|
|
29
|
+
: muiTableFooterCellProps;
|
|
30
|
+
|
|
31
|
+
const mcTableFooterCellProps =
|
|
32
|
+
column.muiTableFooterCellProps instanceof Function
|
|
33
|
+
? column.muiTableFooterCellProps(column)
|
|
34
|
+
: column.muiTableFooterCellProps;
|
|
35
|
+
|
|
36
|
+
const tableCellProps = {
|
|
37
|
+
...mTableFooterCellProps,
|
|
38
|
+
...mcTableFooterCellProps,
|
|
39
|
+
...column.getFooterProps(),
|
|
40
|
+
style: {
|
|
41
|
+
...column.getFooterProps().style,
|
|
42
|
+
...(mTableFooterCellProps?.style ?? {}),
|
|
43
|
+
...(mcTableFooterCellProps?.style ?? {}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
24
47
|
return (
|
|
25
48
|
<TableCell
|
|
26
49
|
align={isParentHeader ? 'center' : 'left'}
|
|
50
|
+
densePadding={densePadding}
|
|
51
|
+
enableColumnResizing={enableColumnResizing}
|
|
27
52
|
variant="head"
|
|
28
|
-
{...
|
|
53
|
+
{...tableCellProps}
|
|
29
54
|
>
|
|
30
55
|
{column.render('Footer')}
|
|
31
56
|
</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,43 @@ 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' && <MRT_TableSpacerCell />}
|
|
32
44
|
{(anyRowsCanExpand || renderDetailPanel) && (
|
|
33
|
-
<
|
|
34
|
-
|
|
35
|
-
width: `${
|
|
36
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
37
|
-
}rem`,
|
|
38
|
-
}}
|
|
45
|
+
<MRT_TableSpacerCell
|
|
46
|
+
width={`${renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5}rem`}
|
|
39
47
|
/>
|
|
40
48
|
)}
|
|
41
49
|
{enableSelection && <MRT_TableSpacerCell width="1rem" />}
|
|
42
|
-
{footerGroup.headers.map((column
|
|
43
|
-
<MRT_TableFooterCell key={
|
|
50
|
+
{footerGroup.headers.map((column) => (
|
|
51
|
+
<MRT_TableFooterCell key={column.getFooterProps().key} column={column} />
|
|
44
52
|
))}
|
|
45
|
-
{
|
|
53
|
+
{enableRowActions && positionActionsColumn === 'last' && <MRT_TableSpacerCell />}
|
|
46
54
|
</TableRow>
|
|
47
55
|
);
|
|
48
56
|
};
|
|
@@ -1,37 +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 ? muiTableHeadProps(tableInstance) : muiTableHeadProps;
|
|
22
13
|
|
|
23
14
|
return (
|
|
24
15
|
<TableHead {...tableHeadProps}>
|
|
25
|
-
{
|
|
26
|
-
|
|
27
|
-
['top', 'both'].includes(positionPagination ?? '') && (
|
|
28
|
-
<MRT_TablePagination />
|
|
29
|
-
)}
|
|
30
|
-
{tableInstance.headerGroups.map((headerGroup, index) => (
|
|
31
|
-
<MRT_TableHeadRow
|
|
32
|
-
key={`${index}-${headerGroup.id}`}
|
|
33
|
-
headerGroup={headerGroup}
|
|
34
|
-
/>
|
|
16
|
+
{tableInstance.headerGroups.map((headerGroup) => (
|
|
17
|
+
<MRT_TableHeadRow key={headerGroup.getHeaderGroupProps().key} headerGroup={headerGroup} />
|
|
35
18
|
))}
|
|
36
19
|
</TableHead>
|
|
37
20
|
);
|
|
@@ -8,24 +8,36 @@ import {
|
|
|
8
8
|
} from '@mui/material';
|
|
9
9
|
import { HeaderGroup } from 'react-table';
|
|
10
10
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
11
|
-
import {
|
|
11
|
+
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
12
12
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
});
|
|
14
|
+
export const StyledTableHeadCell = styled(MuiTableCell, {
|
|
15
|
+
shouldForwardProp: (prop) => prop !== 'densePadding' && prop !== 'enableColumnResizing',
|
|
16
|
+
})<{ densePadding?: boolean; enableColumnResizing?: boolean }>(
|
|
17
|
+
({ densePadding, enableColumnResizing }) => ({
|
|
18
|
+
fontWeight: 'bold',
|
|
19
|
+
height: '100%',
|
|
20
|
+
padding: densePadding ? '0.5rem' : '1rem',
|
|
21
|
+
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
22
|
+
verticalAlign: 'text-top',
|
|
23
|
+
}),
|
|
24
|
+
);
|
|
17
25
|
|
|
18
|
-
const
|
|
26
|
+
const TableCellWrapper = styled('div')({
|
|
27
|
+
alignContent: 'space-between',
|
|
19
28
|
display: 'grid',
|
|
29
|
+
height: '100%',
|
|
20
30
|
});
|
|
21
31
|
|
|
22
|
-
const
|
|
32
|
+
const TableCellTopContents = styled('div')({
|
|
23
33
|
width: '100%',
|
|
24
34
|
display: 'flex',
|
|
25
35
|
justifyContent: 'space-between',
|
|
36
|
+
alignItems: 'flex-start',
|
|
26
37
|
});
|
|
27
38
|
|
|
28
39
|
const CellFlexItem = styled('span')({
|
|
40
|
+
alignItems: 'center',
|
|
29
41
|
display: 'flex',
|
|
30
42
|
flexWrap: 'nowrap',
|
|
31
43
|
});
|
|
@@ -42,41 +54,66 @@ interface Props {
|
|
|
42
54
|
|
|
43
55
|
export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
44
56
|
const {
|
|
45
|
-
|
|
46
|
-
|
|
57
|
+
densePadding,
|
|
58
|
+
disableColumnActions,
|
|
59
|
+
disableFilters,
|
|
47
60
|
enableColumnResizing,
|
|
48
|
-
|
|
49
|
-
|
|
61
|
+
localization,
|
|
62
|
+
muiTableHeadCellProps,
|
|
63
|
+
showFilters,
|
|
50
64
|
tableInstance,
|
|
51
65
|
} = useMaterialReactTable();
|
|
52
66
|
|
|
53
|
-
if (overrideTableHeadCellComponent) {
|
|
54
|
-
return <>{overrideTableHeadCellComponent(column, tableInstance)}</>;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
67
|
const isParentHeader = (column?.columns?.length ?? 0) > 0;
|
|
58
68
|
|
|
69
|
+
const mTableHeadCellProps =
|
|
70
|
+
muiTableHeadCellProps instanceof Function
|
|
71
|
+
? muiTableHeadCellProps(column)
|
|
72
|
+
: muiTableHeadCellProps;
|
|
73
|
+
|
|
74
|
+
const mcTableHeadCellProps =
|
|
75
|
+
column.muiTableHeadCellProps instanceof Function
|
|
76
|
+
? column.muiTableHeadCellProps(column)
|
|
77
|
+
: column.muiTableHeadCellProps;
|
|
78
|
+
|
|
79
|
+
const tableCellProps = {
|
|
80
|
+
...mTableHeadCellProps,
|
|
81
|
+
...mcTableHeadCellProps,
|
|
82
|
+
...column.getHeaderProps(),
|
|
83
|
+
style: {
|
|
84
|
+
...column.getHeaderProps().style,
|
|
85
|
+
...(mTableHeadCellProps?.style ?? {}),
|
|
86
|
+
...(mcTableHeadCellProps?.style ?? {}),
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
|
|
59
90
|
return (
|
|
60
|
-
<
|
|
91
|
+
<StyledTableHeadCell
|
|
61
92
|
align={isParentHeader ? 'center' : 'left'}
|
|
62
|
-
{
|
|
93
|
+
densePadding={densePadding}
|
|
94
|
+
enableColumnResizing={enableColumnResizing}
|
|
95
|
+
{...tableCellProps}
|
|
63
96
|
>
|
|
64
|
-
<
|
|
65
|
-
<
|
|
66
|
-
style={{ justifyContent: isParentHeader ? 'center' : undefined }}
|
|
67
|
-
>
|
|
97
|
+
<TableCellWrapper>
|
|
98
|
+
<TableCellTopContents style={{ justifyContent: isParentHeader ? 'center' : undefined }}>
|
|
68
99
|
<CellFlexItem {...column.getSortByToggleProps()}>
|
|
69
100
|
{column.render('Header')}
|
|
70
101
|
{!isParentHeader && column.canSort && (
|
|
71
102
|
<TableSortLabel
|
|
103
|
+
aria-label={
|
|
104
|
+
column.isSorted
|
|
105
|
+
? column.sortDescFirst
|
|
106
|
+
? localization?.columnActionMenuItemClearSort
|
|
107
|
+
: localization?.columnActionMenuItemSortDesc
|
|
108
|
+
: localization?.columnActionMenuItemSortAsc
|
|
109
|
+
}
|
|
72
110
|
active={column.isSorted}
|
|
73
111
|
direction={column.isSortedDesc ? 'desc' : 'asc'}
|
|
74
|
-
style={{ margin: 0 }}
|
|
75
112
|
/>
|
|
76
113
|
)}
|
|
77
114
|
</CellFlexItem>
|
|
78
115
|
<CellFlexItem>
|
|
79
|
-
{
|
|
116
|
+
{!disableColumnActions && !isParentHeader && (
|
|
80
117
|
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
81
118
|
)}
|
|
82
119
|
{enableColumnResizing && !isParentHeader && (
|
|
@@ -88,13 +125,13 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
88
125
|
/>
|
|
89
126
|
)}
|
|
90
127
|
</CellFlexItem>
|
|
91
|
-
</
|
|
92
|
-
{
|
|
93
|
-
<Collapse in={
|
|
94
|
-
<
|
|
128
|
+
</TableCellTopContents>
|
|
129
|
+
{!disableFilters && column.canFilter && (
|
|
130
|
+
<Collapse in={showFilters}>
|
|
131
|
+
<MRT_FilterTextField column={column} />
|
|
95
132
|
</Collapse>
|
|
96
133
|
)}
|
|
97
|
-
</
|
|
98
|
-
</
|
|
134
|
+
</TableCellWrapper>
|
|
135
|
+
</StyledTableHeadCell>
|
|
99
136
|
);
|
|
100
137
|
};
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { TableRow } from '@mui/material';
|
|
3
3
|
import { HeaderGroup } from 'react-table';
|
|
4
|
-
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
+
import { MRT_TableHeadCell, StyledTableHeadCell } from './MRT_TableHeadCell';
|
|
5
5
|
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
6
6
|
import { MRT_SelectAllCheckbox } from '../inputs/MRT_SelectAllCheckbox';
|
|
7
7
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
8
|
-
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
9
8
|
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
10
9
|
|
|
11
10
|
interface Props {
|
|
@@ -14,34 +13,54 @@ interface Props {
|
|
|
14
13
|
|
|
15
14
|
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
16
15
|
const {
|
|
17
|
-
overrideTableHeadRowComponent,
|
|
18
16
|
anyRowsCanExpand,
|
|
19
|
-
|
|
20
|
-
|
|
17
|
+
densePadding,
|
|
18
|
+
disableExpandAll,
|
|
19
|
+
enableRowActions,
|
|
21
20
|
enableSelection,
|
|
21
|
+
localization,
|
|
22
|
+
muiTableHeadRowProps,
|
|
23
|
+
positionActionsColumn,
|
|
22
24
|
renderDetailPanel,
|
|
23
25
|
tableInstance,
|
|
24
26
|
} = useMaterialReactTable();
|
|
25
27
|
|
|
26
|
-
if (overrideTableHeadRowComponent) {
|
|
27
|
-
return <>{overrideTableHeadRowComponent(headerGroup, tableInstance)}</>;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
28
|
const isParentHeader = useMemo(
|
|
31
29
|
() => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
|
|
32
30
|
[headerGroup.headers],
|
|
33
31
|
);
|
|
34
32
|
|
|
33
|
+
const mTableHeadRowProps =
|
|
34
|
+
muiTableHeadRowProps instanceof Function
|
|
35
|
+
? muiTableHeadRowProps(headerGroup)
|
|
36
|
+
: muiTableHeadRowProps;
|
|
37
|
+
|
|
38
|
+
const tableRowProps = {
|
|
39
|
+
...mTableHeadRowProps,
|
|
40
|
+
...headerGroup.getHeaderGroupProps(),
|
|
41
|
+
style: {
|
|
42
|
+
...headerGroup.getHeaderGroupProps().style,
|
|
43
|
+
...(mTableHeadRowProps?.style ?? {}),
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
35
47
|
return (
|
|
36
|
-
<TableRow {...
|
|
48
|
+
<TableRow {...tableRowProps}>
|
|
49
|
+
{enableRowActions &&
|
|
50
|
+
positionActionsColumn === 'first' &&
|
|
51
|
+
(isParentHeader ? (
|
|
52
|
+
<MRT_TableSpacerCell />
|
|
53
|
+
) : (
|
|
54
|
+
<StyledTableHeadCell style={{ textAlign: 'center' }}>
|
|
55
|
+
{localization?.actionsHeadColumnTitle}
|
|
56
|
+
</StyledTableHeadCell>
|
|
57
|
+
))}
|
|
37
58
|
{anyRowsCanExpand || renderDetailPanel ? (
|
|
38
|
-
|
|
59
|
+
!disableExpandAll && !isParentHeader ? (
|
|
39
60
|
<MRT_ExpandAllButton />
|
|
40
61
|
) : (
|
|
41
62
|
<MRT_TableSpacerCell
|
|
42
|
-
width={`${
|
|
43
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
44
|
-
}rem`}
|
|
63
|
+
width={`${renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5}rem`}
|
|
45
64
|
/>
|
|
46
65
|
)
|
|
47
66
|
) : null}
|
|
@@ -52,10 +71,18 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
|
52
71
|
<MRT_TableSpacerCell width="1rem" />
|
|
53
72
|
)
|
|
54
73
|
) : null}
|
|
55
|
-
{headerGroup.headers.map((column
|
|
56
|
-
<MRT_TableHeadCell key={
|
|
74
|
+
{headerGroup.headers.map((column: HeaderGroup) => (
|
|
75
|
+
<MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
|
|
57
76
|
))}
|
|
58
|
-
{
|
|
77
|
+
{enableRowActions &&
|
|
78
|
+
positionActionsColumn === 'last' &&
|
|
79
|
+
(isParentHeader ? (
|
|
80
|
+
<MRT_TableSpacerCell />
|
|
81
|
+
) : (
|
|
82
|
+
<StyledTableHeadCell densePadding={densePadding}>
|
|
83
|
+
{localization?.actionsHeadColumnTitle}
|
|
84
|
+
</StyledTableHeadCell>
|
|
85
|
+
))}
|
|
59
86
|
</TableRow>
|
|
60
87
|
);
|
|
61
88
|
};
|
package/src/index.tsx
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
MaterialReactTable,
|
|
3
|
-
MaterialReactTableProps,
|
|
4
|
-
} from './MaterialReactTable';
|
|
1
|
+
import MaterialReactTable from './MaterialReactTable';
|
|
5
2
|
export default MaterialReactTable;
|
|
6
|
-
export
|
|
3
|
+
export * from './MaterialReactTable';
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Switch, Tooltip } from '@mui/material';
|
|
3
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
4
|
+
|
|
5
|
+
interface Props {}
|
|
6
|
+
|
|
7
|
+
export const MRT_DensePaddingSwitch: FC<Props> = () => {
|
|
8
|
+
const { densePadding, setDensePadding, localization } = useMaterialReactTable();
|
|
9
|
+
|
|
10
|
+
return (
|
|
11
|
+
<Tooltip arrow title={localization?.toggleDensePaddingSwitchTitle ?? ''}>
|
|
12
|
+
<Switch
|
|
13
|
+
inputProps={{
|
|
14
|
+
'aria-label': localization?.toggleDensePaddingSwitchTitle ?? '',
|
|
15
|
+
}}
|
|
16
|
+
color="default"
|
|
17
|
+
checked={densePadding}
|
|
18
|
+
size="small"
|
|
19
|
+
onChange={() => setDensePadding(!densePadding)}
|
|
20
|
+
/>
|
|
21
|
+
</Tooltip>
|
|
22
|
+
);
|
|
23
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { ChangeEvent, FC } from 'react';
|
|
2
|
+
import { TextField } from '@mui/material';
|
|
3
|
+
import { Cell } from 'react-table';
|
|
4
|
+
import { useMaterialReactTable } from '../useMaterialReactTable';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
cell: Cell;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
11
|
+
const {
|
|
12
|
+
currentEditingRow,
|
|
13
|
+
localization,
|
|
14
|
+
muiTableBodyCellEditTextFieldProps,
|
|
15
|
+
setCurrentEditingRow,
|
|
16
|
+
} = useMaterialReactTable();
|
|
17
|
+
|
|
18
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
19
|
+
if (currentEditingRow) {
|
|
20
|
+
cell.row.values[cell.column.id] = event.target.value;
|
|
21
|
+
setCurrentEditingRow({
|
|
22
|
+
...currentEditingRow,
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
cell.column.onCellEditChange?.(event, cell);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const mTableBodyCellEditTextFieldProps =
|
|
29
|
+
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
30
|
+
? muiTableBodyCellEditTextFieldProps(cell)
|
|
31
|
+
: muiTableBodyCellEditTextFieldProps;
|
|
32
|
+
|
|
33
|
+
const mcTableBodyCellEditTextFieldProps =
|
|
34
|
+
cell.column.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
35
|
+
? cell.column.muiTableBodyCellEditTextFieldProps(cell)
|
|
36
|
+
: cell.column.muiTableBodyCellEditTextFieldProps;
|
|
37
|
+
|
|
38
|
+
const textFieldProps = {
|
|
39
|
+
...mTableBodyCellEditTextFieldProps,
|
|
40
|
+
...mcTableBodyCellEditTextFieldProps,
|
|
41
|
+
style: {
|
|
42
|
+
//@ts-ignore
|
|
43
|
+
...muiTableBodyCellEditTextFieldProps?.style,
|
|
44
|
+
//@ts-ignore
|
|
45
|
+
...cell.column.muiTableBodyCellEditTextFieldProps?.style,
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
if (cell.column.editable && cell.column.Edit) {
|
|
50
|
+
return <>{cell.column.Edit({ ...textFieldProps, cell })}</>;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return (
|
|
54
|
+
<TextField
|
|
55
|
+
margin="dense"
|
|
56
|
+
onChange={handleChange}
|
|
57
|
+
onClick={(e) => e.stopPropagation()}
|
|
58
|
+
placeholder={localization?.filterTextFieldPlaceholder}
|
|
59
|
+
value={cell.value}
|
|
60
|
+
variant="standard"
|
|
61
|
+
{...textFieldProps}
|
|
62
|
+
/>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { ChangeEvent, FC, useState } from 'react';
|
|
2
|
-
import { IconButton, InputAdornment, TextField } from '@mui/material';
|
|
2
|
+
import { IconButton, InputAdornment, TextField, Tooltip } from '@mui/material';
|
|
3
3
|
import CloseIcon from '@mui/icons-material/Close';
|
|
4
4
|
import FilterIcon from '@mui/icons-material/FilterList';
|
|
5
5
|
import { HeaderGroup, useAsyncDebounce } from 'react-table';
|
|
@@ -9,7 +9,7 @@ interface Props {
|
|
|
9
9
|
column: HeaderGroup;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export const
|
|
12
|
+
export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
13
13
|
const { localization } = useMaterialReactTable();
|
|
14
14
|
|
|
15
15
|
const [filterValue, setFilterValue] = useState('');
|
|
@@ -23,10 +23,24 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
23
23
|
column.setFilter(undefined);
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
if (column.Filter) {
|
|
27
|
+
return <>{column.Filter?.({ column })}</>;
|
|
28
|
+
}
|
|
29
|
+
|
|
26
30
|
return (
|
|
27
31
|
<TextField
|
|
32
|
+
fullWidth
|
|
33
|
+
id={`filter-${column.id}-column`}
|
|
34
|
+
inputProps={{
|
|
35
|
+
style: {
|
|
36
|
+
textOverflow: 'ellipsis',
|
|
37
|
+
},
|
|
38
|
+
}}
|
|
28
39
|
margin="dense"
|
|
29
|
-
placeholder={localization?.filterTextFieldPlaceholder
|
|
40
|
+
placeholder={localization?.filterTextFieldPlaceholder?.replace(
|
|
41
|
+
'{column}',
|
|
42
|
+
String(column.Header),
|
|
43
|
+
)}
|
|
30
44
|
onChange={(e: ChangeEvent<HTMLInputElement>) => {
|
|
31
45
|
setFilterValue(e.target.value);
|
|
32
46
|
handleChange(e.target.value);
|
|
@@ -36,21 +50,34 @@ export const MRT_FilterTextfield: FC<Props> = ({ column }) => {
|
|
|
36
50
|
variant="standard"
|
|
37
51
|
InputProps={{
|
|
38
52
|
startAdornment: (
|
|
39
|
-
<
|
|
40
|
-
|
|
41
|
-
|
|
53
|
+
<Tooltip
|
|
54
|
+
arrow
|
|
55
|
+
title={
|
|
56
|
+
localization?.filterTextFieldPlaceholder?.replace(
|
|
57
|
+
'{column}',
|
|
58
|
+
String(column.Header),
|
|
59
|
+
) ?? ''
|
|
60
|
+
}
|
|
61
|
+
>
|
|
62
|
+
<InputAdornment position="start">
|
|
63
|
+
<FilterIcon />
|
|
64
|
+
</InputAdornment>
|
|
65
|
+
</Tooltip>
|
|
42
66
|
),
|
|
43
67
|
endAdornment: (
|
|
44
68
|
<InputAdornment position="end">
|
|
45
|
-
<
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
69
|
+
<Tooltip arrow title={localization?.filterTextFieldClearButtonTitle ?? ''}>
|
|
70
|
+
<span>
|
|
71
|
+
<IconButton
|
|
72
|
+
aria-label={localization?.filterTextFieldClearButtonTitle}
|
|
73
|
+
disabled={filterValue?.length === 0}
|
|
74
|
+
onClick={handleClear}
|
|
75
|
+
size="small"
|
|
76
|
+
>
|
|
77
|
+
<CloseIcon fontSize="small" />
|
|
78
|
+
</IconButton>
|
|
79
|
+
</span>
|
|
80
|
+
</Tooltip>
|
|
54
81
|
</InputAdornment>
|
|
55
82
|
),
|
|
56
83
|
}}
|