material-react-table 0.7.6 → 0.8.0-alpha.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 +13 -15
- package/dist/body/MRT_TableBody.d.ts +0 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/body/MRT_TableBodyRow.d.ts +0 -1
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/enums.d.ts +2 -2
- package/dist/filtersFNs.d.ts +31 -30
- package/dist/footer/MRT_TableFooter.d.ts +0 -1
- package/dist/head/MRT_TableHead.d.ts +0 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
- package/dist/localization.d.ts +6 -2
- package/dist/material-react-table.cjs.development.js +372 -402
- 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 +375 -405
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_Table.d.ts +0 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
- package/dist/utils.d.ts +1 -1
- package/package.json +24 -24
- package/src/MaterialReactTable.tsx +17 -24
- package/src/body/MRT_TableBody.tsx +3 -11
- package/src/body/MRT_TableBodyCell.tsx +102 -51
- package/src/body/MRT_TableBodyRow.tsx +21 -30
- package/src/buttons/MRT_ColumnPinningButtons.tsx +28 -40
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +1 -2
- package/src/enums.ts +2 -2
- package/src/filtersFNs.ts +71 -81
- package/src/footer/MRT_TableFooter.tsx +6 -16
- package/src/footer/MRT_TableFooterCell.tsx +5 -7
- package/src/footer/MRT_TableFooterRow.tsx +5 -8
- package/src/head/MRT_TableHead.tsx +5 -16
- package/src/head/MRT_TableHeadCell.tsx +98 -39
- package/src/head/MRT_TableHeadRow.tsx +8 -15
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/inputs/MRT_FilterTextField.tsx +73 -41
- package/src/inputs/MRT_SelectCheckbox.tsx +16 -17
- package/src/localization.ts +13 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +7 -6
- package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +3 -5
- package/src/table/MRT_Table.tsx +5 -16
- package/src/table/MRT_TableContainer.tsx +7 -78
- package/src/table/MRT_TableRoot.tsx +51 -51
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
package/src/localization.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export interface MRT_Localization {
|
|
2
2
|
actions: string;
|
|
3
|
+
and: string;
|
|
3
4
|
cancel: string;
|
|
4
5
|
changeFilterMode: string;
|
|
5
6
|
changeSearchMode: string;
|
|
@@ -12,13 +13,13 @@ export interface MRT_Localization {
|
|
|
12
13
|
edit: string;
|
|
13
14
|
expand: string;
|
|
14
15
|
expandAll: string;
|
|
15
|
-
|
|
16
|
-
filterBestMatchFirst: string;
|
|
16
|
+
filterBetween: string;
|
|
17
17
|
filterByColumn: string;
|
|
18
18
|
filterContains: string;
|
|
19
19
|
filterEmpty: string;
|
|
20
20
|
filterEndsWith: string;
|
|
21
21
|
filterEquals: string;
|
|
22
|
+
filterFuzzy: string;
|
|
22
23
|
filterGreaterThan: string;
|
|
23
24
|
filterLessThan: string;
|
|
24
25
|
filterMode: string;
|
|
@@ -30,6 +31,8 @@ export interface MRT_Localization {
|
|
|
30
31
|
groupedBy: string;
|
|
31
32
|
hideAll: string;
|
|
32
33
|
hideColumn: string;
|
|
34
|
+
max: string;
|
|
35
|
+
min: string;
|
|
33
36
|
pinToLeft: string;
|
|
34
37
|
pinToRight: string;
|
|
35
38
|
resetColumnSize: string;
|
|
@@ -50,6 +53,7 @@ export interface MRT_Localization {
|
|
|
50
53
|
sortedByColumnAsc: string;
|
|
51
54
|
sortedByColumnDesc: string;
|
|
52
55
|
thenBy: string;
|
|
56
|
+
to: string;
|
|
53
57
|
toggleDensePadding: string;
|
|
54
58
|
toggleFullScreen: string;
|
|
55
59
|
toggleSelectAll: string;
|
|
@@ -62,6 +66,7 @@ export interface MRT_Localization {
|
|
|
62
66
|
|
|
63
67
|
export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
64
68
|
actions: 'Actions',
|
|
69
|
+
and: 'and',
|
|
65
70
|
cancel: 'Cancel',
|
|
66
71
|
changeFilterMode: 'Change filter mode',
|
|
67
72
|
changeSearchMode: 'Change search mode',
|
|
@@ -74,24 +79,26 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
74
79
|
edit: 'Edit',
|
|
75
80
|
expand: 'Expand',
|
|
76
81
|
expandAll: 'Expand all',
|
|
77
|
-
|
|
78
|
-
filterBestMatchFirst: 'Best Match First',
|
|
82
|
+
filterBetween: 'Between',
|
|
79
83
|
filterByColumn: 'Filter by {column}',
|
|
80
84
|
filterContains: 'Contains',
|
|
81
85
|
filterEmpty: 'Empty',
|
|
82
86
|
filterEndsWith: 'Ends With',
|
|
83
87
|
filterEquals: 'Equals',
|
|
88
|
+
filterFuzzy: 'Fuzzy',
|
|
84
89
|
filterGreaterThan: 'Greater Than',
|
|
85
90
|
filterLessThan: 'Less Than',
|
|
86
91
|
filterMode: 'Filter Mode: {filterType}',
|
|
87
92
|
filterNotEmpty: 'Not Empty',
|
|
88
93
|
filterNotEquals: 'Not Equals',
|
|
89
94
|
filterStartsWith: 'Starts With',
|
|
90
|
-
filteringByColumn: 'Filtering by {column} - {filterType}
|
|
95
|
+
filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
|
|
91
96
|
groupByColumn: 'Group by {column}',
|
|
92
97
|
groupedBy: 'Grouped by ',
|
|
93
98
|
hideAll: 'Hide all',
|
|
94
99
|
hideColumn: 'Hide {column} column',
|
|
100
|
+
max: 'Max',
|
|
101
|
+
min: 'Min',
|
|
95
102
|
pinToLeft: 'Pin to left',
|
|
96
103
|
pinToRight: 'Pin to right',
|
|
97
104
|
resetColumnSize: 'Reset column size',
|
|
@@ -113,6 +120,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
113
120
|
sortedByColumnAsc: 'Sorted by {column} ascending',
|
|
114
121
|
sortedByColumnDesc: 'Sorted by {column} descending',
|
|
115
122
|
thenBy: ', then by ',
|
|
123
|
+
to: 'to',
|
|
116
124
|
toggleDensePadding: 'Toggle dense padding',
|
|
117
125
|
toggleFullScreen: 'Toggle full screen',
|
|
118
126
|
toggleSelectAll: 'Toggle select all',
|
|
@@ -69,7 +69,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
69
69
|
useState<null | HTMLElement>(null);
|
|
70
70
|
|
|
71
71
|
const handleClearSort = () => {
|
|
72
|
-
column.
|
|
72
|
+
column.clearSorting();
|
|
73
73
|
setAnchorEl(null);
|
|
74
74
|
};
|
|
75
75
|
|
|
@@ -95,6 +95,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
95
95
|
|
|
96
96
|
const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
|
|
97
97
|
column.pin(pinDirection);
|
|
98
|
+
setAnchorEl(null);
|
|
98
99
|
};
|
|
99
100
|
|
|
100
101
|
const handleGroupByColumn = () => {
|
|
@@ -104,7 +105,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
104
105
|
};
|
|
105
106
|
|
|
106
107
|
const handleClearFilter = () => {
|
|
107
|
-
column.
|
|
108
|
+
column.setFilterValue('');
|
|
108
109
|
setAnchorEl(null);
|
|
109
110
|
};
|
|
110
111
|
|
|
@@ -200,9 +201,9 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
200
201
|
</MenuItem>,
|
|
201
202
|
]}
|
|
202
203
|
{enableColumnFilters &&
|
|
203
|
-
column.
|
|
204
|
+
column.getCanFilter() && [
|
|
204
205
|
<MenuItem
|
|
205
|
-
disabled={!column.
|
|
206
|
+
disabled={!column.getFilterValue()}
|
|
206
207
|
key={0}
|
|
207
208
|
onClick={handleClearFilter}
|
|
208
209
|
sx={commonMenuItemStyles}
|
|
@@ -284,7 +285,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
284
285
|
</MenuItem>,
|
|
285
286
|
<MenuItem
|
|
286
287
|
disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
|
|
287
|
-
key={
|
|
288
|
+
key={1}
|
|
288
289
|
onClick={() => handlePinColumn('right')}
|
|
289
290
|
sx={commonMenuItemStyles}
|
|
290
291
|
>
|
|
@@ -298,7 +299,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
298
299
|
<MenuItem
|
|
299
300
|
disabled={!column.getIsPinned()}
|
|
300
301
|
divider={enableHiding}
|
|
301
|
-
key={
|
|
302
|
+
key={2}
|
|
302
303
|
onClick={() => handlePinColumn(false)}
|
|
303
304
|
sx={commonMenuItemStyles}
|
|
304
305
|
>
|
|
@@ -3,12 +3,12 @@ import { Menu, MenuItem } from '@mui/material';
|
|
|
3
3
|
import type { MRT_FilterFn, MRT_Header, MRT_TableInstance } from '..';
|
|
4
4
|
import { MRT_FILTER_OPTION } from '../enums';
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
bestMatchFirst,
|
|
6
|
+
between,
|
|
8
7
|
contains,
|
|
9
8
|
empty,
|
|
10
9
|
endsWith,
|
|
11
10
|
equals,
|
|
11
|
+
fuzzy,
|
|
12
12
|
greaterThan,
|
|
13
13
|
lessThan,
|
|
14
14
|
notEmpty,
|
|
@@ -48,7 +48,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
48
48
|
getState();
|
|
49
49
|
|
|
50
50
|
const filterOptions: {
|
|
51
|
-
|
|
51
|
+
option: MRT_FILTER_OPTION;
|
|
52
52
|
label: string;
|
|
53
53
|
divider: boolean;
|
|
54
54
|
fn: Function;
|
|
@@ -56,67 +56,67 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
56
56
|
() =>
|
|
57
57
|
[
|
|
58
58
|
{
|
|
59
|
-
|
|
60
|
-
label: localization.
|
|
59
|
+
option: MRT_FILTER_OPTION.FUZZY,
|
|
60
|
+
label: localization.filterFuzzy,
|
|
61
61
|
divider: false,
|
|
62
|
-
fn:
|
|
62
|
+
fn: fuzzy,
|
|
63
63
|
},
|
|
64
64
|
{
|
|
65
|
-
|
|
66
|
-
label: localization.filterBestMatch,
|
|
67
|
-
divider: !!header,
|
|
68
|
-
fn: bestMatch,
|
|
69
|
-
},
|
|
70
|
-
{
|
|
71
|
-
type: MRT_FILTER_OPTION.CONTAINS,
|
|
65
|
+
option: MRT_FILTER_OPTION.CONTAINS,
|
|
72
66
|
label: localization.filterContains,
|
|
73
67
|
divider: false,
|
|
74
68
|
fn: contains,
|
|
75
69
|
},
|
|
76
70
|
{
|
|
77
|
-
|
|
71
|
+
option: MRT_FILTER_OPTION.STARTS_WITH,
|
|
78
72
|
label: localization.filterStartsWith,
|
|
79
73
|
divider: false,
|
|
80
74
|
fn: startsWith,
|
|
81
75
|
},
|
|
82
76
|
{
|
|
83
|
-
|
|
77
|
+
option: MRT_FILTER_OPTION.ENDS_WITH,
|
|
84
78
|
label: localization.filterEndsWith,
|
|
85
79
|
divider: true,
|
|
86
80
|
fn: endsWith,
|
|
87
81
|
},
|
|
88
82
|
{
|
|
89
|
-
|
|
83
|
+
option: MRT_FILTER_OPTION.EQUALS,
|
|
90
84
|
label: localization.filterEquals,
|
|
91
85
|
divider: false,
|
|
92
86
|
fn: equals,
|
|
93
87
|
},
|
|
94
88
|
{
|
|
95
|
-
|
|
89
|
+
option: MRT_FILTER_OPTION.NOT_EQUALS,
|
|
96
90
|
label: localization.filterNotEquals,
|
|
97
91
|
divider: true,
|
|
98
92
|
fn: notEquals,
|
|
99
93
|
},
|
|
100
94
|
{
|
|
101
|
-
|
|
95
|
+
option: MRT_FILTER_OPTION.BETWEEN,
|
|
96
|
+
label: localization.filterBetween,
|
|
97
|
+
divider: false,
|
|
98
|
+
fn: between,
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
option: MRT_FILTER_OPTION.GREATER_THAN,
|
|
102
102
|
label: localization.filterGreaterThan,
|
|
103
103
|
divider: false,
|
|
104
104
|
fn: greaterThan,
|
|
105
105
|
},
|
|
106
106
|
{
|
|
107
|
-
|
|
107
|
+
option: MRT_FILTER_OPTION.LESS_THAN,
|
|
108
108
|
label: localization.filterLessThan,
|
|
109
109
|
divider: true,
|
|
110
110
|
fn: lessThan,
|
|
111
111
|
},
|
|
112
112
|
{
|
|
113
|
-
|
|
113
|
+
option: MRT_FILTER_OPTION.EMPTY,
|
|
114
114
|
label: localization.filterEmpty,
|
|
115
115
|
divider: false,
|
|
116
116
|
fn: empty,
|
|
117
117
|
},
|
|
118
118
|
{
|
|
119
|
-
|
|
119
|
+
option: MRT_FILTER_OPTION.NOT_EMPTY,
|
|
120
120
|
label: localization.filterNotEmpty,
|
|
121
121
|
divider: false,
|
|
122
122
|
fn: notEmpty,
|
|
@@ -124,13 +124,12 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
124
124
|
].filter((filterType) =>
|
|
125
125
|
header
|
|
126
126
|
? !header.column.enabledColumnFilterOptions ||
|
|
127
|
-
header.column.enabledColumnFilterOptions.includes(filterType.
|
|
127
|
+
header.column.enabledColumnFilterOptions.includes(filterType.option)
|
|
128
128
|
: (!enabledGlobalFilterOptions ||
|
|
129
|
-
enabledGlobalFilterOptions.includes(filterType.
|
|
130
|
-
[
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
].includes(filterType.type),
|
|
129
|
+
enabledGlobalFilterOptions.includes(filterType.option)) &&
|
|
130
|
+
[MRT_FILTER_OPTION.FUZZY, MRT_FILTER_OPTION.CONTAINS].includes(
|
|
131
|
+
filterType.option,
|
|
132
|
+
),
|
|
134
133
|
),
|
|
135
134
|
[],
|
|
136
135
|
);
|
|
@@ -144,7 +143,11 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
144
143
|
if (
|
|
145
144
|
[MRT_FILTER_OPTION.EMPTY, MRT_FILTER_OPTION.NOT_EMPTY].includes(value)
|
|
146
145
|
) {
|
|
147
|
-
header.column.
|
|
146
|
+
header.column.setFilterValue(' ');
|
|
147
|
+
} else if (value === MRT_FILTER_OPTION.BETWEEN) {
|
|
148
|
+
header.column.setFilterValue(['', '']);
|
|
149
|
+
} else {
|
|
150
|
+
header.column.setFilterValue('');
|
|
148
151
|
}
|
|
149
152
|
} else {
|
|
150
153
|
setCurrentGlobalFilterFn(value);
|
|
@@ -153,7 +156,7 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
153
156
|
onSelect?.();
|
|
154
157
|
};
|
|
155
158
|
|
|
156
|
-
const
|
|
159
|
+
const filterOption = !!header
|
|
157
160
|
? currentFilterFns[header.id]
|
|
158
161
|
: currentGlobalFilterFn;
|
|
159
162
|
|
|
@@ -167,14 +170,14 @@ export const MRT_FilterOptionMenu: FC<Props> = ({
|
|
|
167
170
|
dense: isDensePadding,
|
|
168
171
|
}}
|
|
169
172
|
>
|
|
170
|
-
{filterOptions.map(({
|
|
173
|
+
{filterOptions.map(({ option, label, divider, fn }, index) => (
|
|
171
174
|
<MenuItem
|
|
172
175
|
divider={divider}
|
|
173
176
|
key={index}
|
|
174
|
-
onClick={() => handleSelectFilterType(
|
|
175
|
-
selected={
|
|
177
|
+
onClick={() => handleSelectFilterType(option)}
|
|
178
|
+
selected={option === filterOption || fn === filterOption}
|
|
176
179
|
sx={commonMenuItemStyles}
|
|
177
|
-
value={
|
|
180
|
+
value={option}
|
|
178
181
|
>
|
|
179
182
|
{label}
|
|
180
183
|
</MenuItem>
|
|
@@ -83,7 +83,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
83
83
|
{!isSubMenu && enablePinning && (
|
|
84
84
|
<Button
|
|
85
85
|
disabled={!getIsSomeColumnsPinned()}
|
|
86
|
-
onClick={() => tableInstance.
|
|
86
|
+
onClick={() => tableInstance.resetColumnPinning(true)}
|
|
87
87
|
>
|
|
88
88
|
{localization.unpinAll}
|
|
89
89
|
</Button>
|
|
@@ -16,7 +16,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: { onToggleColumnVisibility
|
|
19
|
+
options: { onToggleColumnVisibility },
|
|
20
20
|
} = tableInstance;
|
|
21
21
|
|
|
22
22
|
const { columnVisibility } = getState();
|
|
@@ -52,7 +52,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
52
52
|
py: '6px',
|
|
53
53
|
}}
|
|
54
54
|
>
|
|
55
|
-
{!isSubMenu &&
|
|
55
|
+
{!isSubMenu && column.getCanPin() && (
|
|
56
56
|
<MRT_ColumnPinningButtons
|
|
57
57
|
column={column}
|
|
58
58
|
tableInstance={tableInstance}
|
|
@@ -62,9 +62,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
62
62
|
componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
|
|
63
63
|
checked={switchChecked}
|
|
64
64
|
control={<Switch />}
|
|
65
|
-
disabled={
|
|
66
|
-
(isSubMenu && switchChecked) || column.enableHiding === false
|
|
67
|
-
}
|
|
65
|
+
disabled={(isSubMenu && switchChecked) || !column.getCanHide()}
|
|
68
66
|
label={column.header}
|
|
69
67
|
onChange={() => handleToggleColumnHidden(column)}
|
|
70
68
|
/>
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -6,13 +6,11 @@ import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
|
|
6
6
|
import { MRT_TableInstance } from '..';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
|
-
pinned: 'left' | 'center' | 'right' | 'none';
|
|
10
9
|
tableInstance: MRT_TableInstance;
|
|
11
10
|
}
|
|
12
11
|
|
|
13
|
-
export const MRT_Table: FC<Props> = ({
|
|
12
|
+
export const MRT_Table: FC<Props> = ({ tableInstance }) => {
|
|
14
13
|
const {
|
|
15
|
-
getTableProps,
|
|
16
14
|
options: {
|
|
17
15
|
enableStickyHeader,
|
|
18
16
|
enableTableFooter,
|
|
@@ -21,25 +19,16 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
21
19
|
},
|
|
22
20
|
} = tableInstance;
|
|
23
21
|
|
|
24
|
-
const
|
|
22
|
+
const tableProps =
|
|
25
23
|
muiTableProps instanceof Function
|
|
26
24
|
? muiTableProps({ tableInstance })
|
|
27
25
|
: muiTableProps;
|
|
28
26
|
|
|
29
|
-
const tableProps = {
|
|
30
|
-
...getTableProps(),
|
|
31
|
-
...mTableProps,
|
|
32
|
-
};
|
|
33
|
-
|
|
34
27
|
return (
|
|
35
28
|
<Table stickyHeader={enableStickyHeader} {...tableProps}>
|
|
36
|
-
{enableTableHead &&
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
<MRT_TableBody pinned={pinned} tableInstance={tableInstance} />
|
|
40
|
-
{enableTableFooter && (
|
|
41
|
-
<MRT_TableFooter pinned={pinned} tableInstance={tableInstance} />
|
|
42
|
-
)}
|
|
29
|
+
{enableTableHead && <MRT_TableHead tableInstance={tableInstance} />}
|
|
30
|
+
<MRT_TableBody tableInstance={tableInstance} />
|
|
31
|
+
{enableTableFooter && <MRT_TableFooter tableInstance={tableInstance} />}
|
|
43
32
|
</Table>
|
|
44
33
|
);
|
|
45
34
|
};
|
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, { FC, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { TableContainer } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
import { MRT_Table } from './MRT_Table';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
theme,
|
|
9
|
-
visible,
|
|
10
|
-
}: {
|
|
11
|
-
pinned?: 'left' | 'right';
|
|
12
|
-
theme: Theme;
|
|
13
|
-
visible?: boolean;
|
|
14
|
-
}): CSSProperties => ({
|
|
15
|
-
display: 'grid',
|
|
16
|
-
minWidth: visible ? '200px' : 0,
|
|
17
|
-
overflowX: pinned ? 'scroll' : 'auto',
|
|
18
|
-
boxShadow:
|
|
19
|
-
pinned === 'left'
|
|
20
|
-
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
21
|
-
: pinned === 'right'
|
|
22
|
-
? `0 -1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
23
|
-
: 'none',
|
|
24
|
-
});
|
|
6
|
+
const useIsomorphicLayoutEffect =
|
|
7
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
25
8
|
|
|
26
9
|
interface Props {
|
|
27
10
|
tableInstance: MRT_TableInstance;
|
|
@@ -29,16 +12,8 @@ interface Props {
|
|
|
29
12
|
|
|
30
13
|
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
31
14
|
const {
|
|
32
|
-
getCenterTableWidth,
|
|
33
|
-
getLeftTableWidth,
|
|
34
|
-
getRightTableWidth,
|
|
35
15
|
getState,
|
|
36
|
-
options: {
|
|
37
|
-
enablePinning,
|
|
38
|
-
enableStickyHeader,
|
|
39
|
-
idPrefix,
|
|
40
|
-
muiTableContainerProps,
|
|
41
|
-
},
|
|
16
|
+
options: { enableStickyHeader, idPrefix, muiTableContainerProps },
|
|
42
17
|
} = tableInstance;
|
|
43
18
|
|
|
44
19
|
const { isFullScreen } = getState();
|
|
@@ -50,7 +25,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
50
25
|
? muiTableContainerProps({ tableInstance })
|
|
51
26
|
: muiTableContainerProps;
|
|
52
27
|
|
|
53
|
-
|
|
28
|
+
useIsomorphicLayoutEffect(() => {
|
|
54
29
|
const topToolbarHeight =
|
|
55
30
|
typeof document !== 'undefined'
|
|
56
31
|
? document?.getElementById(`mrt-${idPrefix}-toolbar-top`)
|
|
@@ -66,9 +41,6 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
66
41
|
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
|
67
42
|
});
|
|
68
43
|
|
|
69
|
-
const isSomeColumnsPinnedLeft = !!tableInstance.getLeftFlatHeaders().length;
|
|
70
|
-
const isSomeColumnsPinnedRight = !!tableInstance.getRightFlatHeaders().length;
|
|
71
|
-
|
|
72
44
|
return (
|
|
73
45
|
<TableContainer
|
|
74
46
|
{...tableContainerProps}
|
|
@@ -86,50 +58,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
86
58
|
: undefined,
|
|
87
59
|
}}
|
|
88
60
|
>
|
|
89
|
-
{
|
|
90
|
-
isSomeColumnsPinnedRight ? (
|
|
91
|
-
<Box
|
|
92
|
-
sx={{
|
|
93
|
-
display: 'grid',
|
|
94
|
-
gridTemplateColumns: `${getLeftTableWidth()}fr ${getCenterTableWidth()}fr ${getRightTableWidth()}fr`,
|
|
95
|
-
}}
|
|
96
|
-
>
|
|
97
|
-
<Box
|
|
98
|
-
sx={(theme: Theme) =>
|
|
99
|
-
commonBoxStyles({
|
|
100
|
-
pinned: 'left',
|
|
101
|
-
theme,
|
|
102
|
-
visible: isSomeColumnsPinnedLeft,
|
|
103
|
-
})
|
|
104
|
-
}
|
|
105
|
-
>
|
|
106
|
-
<MRT_Table pinned="left" tableInstance={tableInstance} />
|
|
107
|
-
</Box>
|
|
108
|
-
<Box
|
|
109
|
-
sx={(theme: Theme) =>
|
|
110
|
-
commonBoxStyles({
|
|
111
|
-
theme,
|
|
112
|
-
visible: !!tableInstance.getCenterFlatHeaders().length,
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
>
|
|
116
|
-
<MRT_Table pinned="center" tableInstance={tableInstance} />
|
|
117
|
-
</Box>
|
|
118
|
-
<Box
|
|
119
|
-
sx={(theme: Theme) =>
|
|
120
|
-
commonBoxStyles({
|
|
121
|
-
pinned: 'right',
|
|
122
|
-
theme,
|
|
123
|
-
visible: isSomeColumnsPinnedRight,
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
>
|
|
127
|
-
<MRT_Table pinned="right" tableInstance={tableInstance} />
|
|
128
|
-
</Box>
|
|
129
|
-
</Box>
|
|
130
|
-
) : (
|
|
131
|
-
<MRT_Table pinned="none" tableInstance={tableInstance} />
|
|
132
|
-
)}
|
|
61
|
+
<MRT_Table tableInstance={tableInstance} />
|
|
133
62
|
</TableContainer>
|
|
134
63
|
);
|
|
135
64
|
};
|