material-react-table 0.6.10 → 0.7.0-alpha.3
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 +27 -17
- package/dist/MaterialReactTable.d.ts +306 -109
- package/dist/body/MRT_TableBody.d.ts +3 -0
- package/dist/body/MRT_TableBodyCell.d.ts +2 -11
- package/dist/body/MRT_TableBodyRow.d.ts +3 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/buttons/MRT_CopyButton.d.ts +4 -2
- package/dist/buttons/MRT_EditActionButtons.d.ts +2 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +2 -0
- package/dist/buttons/MRT_ExpandButton.d.ts +2 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +2 -0
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleColumnActionMenuButton.d.ts +3 -2
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +2 -0
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +2 -1
- package/dist/buttons/MRT_ToggleSearchButton.d.ts +2 -0
- package/dist/footer/MRT_TableFooter.d.ts +3 -0
- package/dist/footer/MRT_TableFooterCell.d.ts +3 -2
- package/dist/footer/MRT_TableFooterRow.d.ts +2 -1
- package/dist/head/MRT_TableHead.d.ts +3 -0
- package/dist/head/MRT_TableHeadCell.d.ts +4 -18
- package/dist/head/MRT_TableHeadRow.d.ts +2 -1
- package/dist/icons.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +2 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +3 -2
- package/dist/inputs/MRT_SearchTextField.d.ts +2 -0
- package/dist/inputs/MRT_SelectCheckbox.d.ts +2 -1
- package/dist/localization.d.ts +7 -2
- package/dist/material-react-table.cjs.development.js +2209 -2483
- 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 +2210 -2484
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +3 -2
- package/dist/menus/MRT_FilterTypeMenu.d.ts +4 -3
- package/dist/menus/MRT_RowActionMenu.d.ts +3 -2
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +2 -0
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -1
- package/dist/table/MRT_Table.d.ts +3 -0
- package/dist/table/MRT_TableContainer.d.ts +2 -0
- package/dist/table/MRT_TablePaper.d.ts +7 -0
- package/dist/table/MRT_TableRoot.d.ts +3 -0
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +2 -0
- package/dist/toolbar/MRT_TablePagination.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +2 -0
- package/dist/toolbar/MRT_ToolbarTop.d.ts +4 -2
- package/dist/utils.d.ts +12 -2
- package/package.json +28 -29
- package/src/MaterialReactTable.tsx +594 -300
- package/src/body/MRT_TableBody.tsx +26 -22
- package/src/body/MRT_TableBodyCell.tsx +75 -60
- package/src/body/MRT_TableBodyRow.tsx +37 -76
- package/src/body/MRT_TableDetailPanel.tsx +21 -17
- package/src/buttons/MRT_CopyButton.tsx +16 -9
- package/src/buttons/MRT_EditActionButtons.tsx +16 -13
- package/src/buttons/MRT_ExpandAllButton.tsx +24 -9
- package/src/buttons/MRT_ExpandButton.tsx +22 -15
- package/src/buttons/MRT_FullScreenToggleButton.tsx +18 -11
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +18 -7
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +22 -11
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +18 -11
- package/src/buttons/MRT_ToggleFiltersButton.tsx +16 -9
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +27 -22
- package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
- package/src/footer/MRT_TableFooter.tsx +24 -8
- package/src/footer/MRT_TableFooterCell.tsx +34 -26
- package/src/footer/MRT_TableFooterRow.tsx +21 -39
- package/src/head/MRT_TableHead.tsx +24 -8
- package/src/head/MRT_TableHeadCell.tsx +184 -142
- package/src/head/MRT_TableHeadRow.tsx +16 -104
- package/src/icons.ts +3 -3
- package/src/inputs/MRT_EditCellTextField.tsx +23 -24
- package/src/inputs/MRT_FilterTextField.tsx +53 -32
- package/src/inputs/MRT_SearchTextField.tsx +46 -24
- package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
- package/src/localization.ts +13 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +28 -22
- package/src/menus/MRT_RowActionMenu.tsx +21 -14
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +52 -20
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +27 -17
- package/src/table/MRT_Table.tsx +25 -15
- package/src/table/MRT_TableContainer.tsx +106 -45
- package/src/table/MRT_TablePaper.tsx +65 -0
- package/src/table/MRT_TableRoot.tsx +236 -0
- package/src/toolbar/MRT_LinearProgressBar.tsx +10 -7
- package/src/toolbar/MRT_TablePagination.tsx +33 -19
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +33 -20
- package/src/toolbar/MRT_ToolbarBottom.tsx +32 -21
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +34 -20
- package/src/toolbar/MRT_ToolbarTop.tsx +36 -29
- package/src/utils.ts +37 -8
- package/dist/head/MRT_TableHeadCellActions.d.ts +0 -5
- package/dist/table/MRT_TableSpacerCell.d.ts +0 -6
- package/dist/useMRT.d.ts +0 -28
- package/src/@types/faker.d.ts +0 -4
- package/src/@types/react-table-config.d.ts +0 -53
- package/src/head/MRT_TableHeadCellActions.tsx +0 -29
- package/src/table/MRT_TableSpacerCell.tsx +0 -20
- package/src/useMRT.tsx +0 -226
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
TableCell,
|
|
4
4
|
TableSortLabel,
|
|
@@ -7,86 +7,64 @@ import {
|
|
|
7
7
|
Tooltip,
|
|
8
8
|
Box,
|
|
9
9
|
IconButton,
|
|
10
|
+
alpha,
|
|
11
|
+
Theme,
|
|
10
12
|
} from '@mui/material';
|
|
11
|
-
import { useMRT } from '../useMRT';
|
|
12
13
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
13
14
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
14
|
-
import type {
|
|
15
|
-
|
|
16
|
-
export const commonTableHeadCellStyles = (
|
|
17
|
-
densePadding: boolean,
|
|
18
|
-
enableColumnResizing?: boolean,
|
|
19
|
-
widths?: {
|
|
20
|
-
maxWidth?: CSSProperties['maxWidth'];
|
|
21
|
-
minWidth?: CSSProperties['minWidth'];
|
|
22
|
-
width?: CSSProperties['width'];
|
|
23
|
-
},
|
|
24
|
-
) => ({
|
|
25
|
-
fontWeight: 'bold',
|
|
26
|
-
height: '100%',
|
|
27
|
-
p: densePadding ? '0.5rem' : '1rem',
|
|
28
|
-
pt: densePadding ? '0.75rem' : '1.25rem',
|
|
29
|
-
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
30
|
-
verticalAlign: 'text-top',
|
|
31
|
-
...widths,
|
|
32
|
-
});
|
|
15
|
+
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
16
|
+
import { ColumnResizerProps } from '@tanstack/react-table';
|
|
33
17
|
|
|
34
18
|
interface Props {
|
|
35
|
-
|
|
19
|
+
header: MRT_Header;
|
|
20
|
+
tableInstance: MRT_TableInstance;
|
|
36
21
|
}
|
|
37
22
|
|
|
38
|
-
export const MRT_TableHeadCell: FC<Props> = ({
|
|
23
|
+
export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
39
24
|
const {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
25
|
+
getState,
|
|
26
|
+
options: {
|
|
27
|
+
enableColumnActions,
|
|
28
|
+
enableColumnFilters,
|
|
29
|
+
enableColumnResizing,
|
|
30
|
+
icons: { FilterAltIcon, FilterAltOff },
|
|
31
|
+
localization,
|
|
32
|
+
muiTableHeadCellProps,
|
|
33
|
+
setShowFilters,
|
|
34
|
+
},
|
|
35
|
+
} = tableInstance;
|
|
36
|
+
|
|
37
|
+
const { isDensePadding, showFilters } = getState();
|
|
49
38
|
|
|
50
|
-
const
|
|
39
|
+
const { column } = header;
|
|
51
40
|
|
|
52
41
|
const mTableHeadCellProps =
|
|
53
42
|
muiTableHeadCellProps instanceof Function
|
|
54
|
-
? muiTableHeadCellProps(column)
|
|
43
|
+
? muiTableHeadCellProps({ column, tableInstance })
|
|
55
44
|
: muiTableHeadCellProps;
|
|
56
45
|
|
|
57
46
|
const mcTableHeadCellProps =
|
|
58
47
|
column.muiTableHeadCellProps instanceof Function
|
|
59
|
-
? column.muiTableHeadCellProps(column)
|
|
48
|
+
? column.muiTableHeadCellProps({ column, tableInstance })
|
|
60
49
|
: column.muiTableHeadCellProps;
|
|
61
50
|
|
|
62
51
|
const tableCellProps = {
|
|
52
|
+
...header.getHeaderProps(),
|
|
63
53
|
...mTableHeadCellProps,
|
|
64
54
|
...mcTableHeadCellProps,
|
|
65
|
-
...column.getHeaderProps(),
|
|
66
|
-
style: {
|
|
67
|
-
...column.getHeaderProps().style,
|
|
68
|
-
...mTableHeadCellProps?.style,
|
|
69
|
-
...mcTableHeadCellProps?.style,
|
|
70
|
-
},
|
|
71
55
|
};
|
|
72
56
|
|
|
73
|
-
const sortTooltip = column.
|
|
74
|
-
? column.
|
|
57
|
+
const sortTooltip = !!column.getIsSorted()
|
|
58
|
+
? column.getIsSorted() === 'desc'
|
|
75
59
|
? localization.clearSort
|
|
76
|
-
: localization.sortByColumnDesc
|
|
77
|
-
|
|
78
|
-
column.Header as string,
|
|
79
|
-
)
|
|
80
|
-
: localization.sortByColumnAsc?.replace(
|
|
81
|
-
'{column}',
|
|
82
|
-
column.Header as string,
|
|
83
|
-
);
|
|
60
|
+
: localization.sortByColumnDesc.replace('{column}', column.header)
|
|
61
|
+
: localization.sortByColumnAsc.replace('{column}', column.header);
|
|
84
62
|
|
|
85
|
-
const filterType =
|
|
63
|
+
const filterType = getState()?.currentFilterTypes?.[header.id];
|
|
86
64
|
|
|
87
|
-
const filterTooltip = !!column.
|
|
65
|
+
const filterTooltip = !!column.getColumnFilterValue()
|
|
88
66
|
? localization.filteringByColumn
|
|
89
|
-
.replace('{column}', String(column.
|
|
67
|
+
.replace('{column}', String(column.header))
|
|
90
68
|
.replace(
|
|
91
69
|
'{filterType}',
|
|
92
70
|
filterType instanceof Function
|
|
@@ -98,112 +76,176 @@ export const MRT_TableHeadCell: FC<Props> = ({ column }) => {
|
|
|
98
76
|
}`
|
|
99
77
|
],
|
|
100
78
|
)
|
|
101
|
-
.replace('{filterValue}', column.
|
|
79
|
+
.replace('{filterValue}', column.getColumnFilterValue() as string)
|
|
102
80
|
.replace('" "', '')
|
|
103
81
|
: localization.showHideFilters;
|
|
104
82
|
|
|
105
|
-
const
|
|
83
|
+
const headerElement =
|
|
84
|
+
column?.Header?.({
|
|
85
|
+
header,
|
|
86
|
+
tableInstance,
|
|
87
|
+
}) ?? column.header;
|
|
106
88
|
|
|
107
89
|
return (
|
|
108
90
|
<TableCell
|
|
109
|
-
align={
|
|
91
|
+
align={column.columnDefType === 'group' ? 'center' : 'left'}
|
|
110
92
|
{...tableCellProps}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
93
|
+
//@ts-ignore
|
|
94
|
+
sx={(theme: Theme) => ({
|
|
95
|
+
backgroundColor: theme.palette.background.default,
|
|
96
|
+
backgroundImage: `linear-gradient(${alpha(
|
|
97
|
+
theme.palette.common.white,
|
|
98
|
+
0.05,
|
|
99
|
+
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
100
|
+
boxShadow: `3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
101
|
+
fontWeight: 'bold',
|
|
102
|
+
height: '100%',
|
|
103
|
+
minWidth: `max(${header.getWidth()}, 100px)`,
|
|
104
|
+
p: isDensePadding
|
|
105
|
+
? column.columnDefType === 'display'
|
|
106
|
+
? '0 0.5rem'
|
|
107
|
+
: '0.5rem'
|
|
108
|
+
: column.columnDefType === 'display'
|
|
109
|
+
? '0.5rem 0.75rem'
|
|
110
|
+
: '1rem',
|
|
111
|
+
pt:
|
|
112
|
+
column.columnDefType === 'display'
|
|
113
|
+
? 0
|
|
114
|
+
: isDensePadding
|
|
115
|
+
? '0.75rem'
|
|
116
|
+
: '1.25rem',
|
|
117
|
+
pb: column.columnDefType === 'display' ? 0 : undefined,
|
|
118
|
+
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
119
|
+
verticalAlign: 'text-top',
|
|
120
|
+
width: header.getWidth(),
|
|
121
|
+
//@ts-ignore
|
|
121
122
|
...tableCellProps?.sx,
|
|
122
|
-
}}
|
|
123
|
+
})}
|
|
123
124
|
>
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
display: 'flex',
|
|
128
|
-
justifyContent: isParentHeader ? 'center' : 'space-between',
|
|
129
|
-
width: '100%',
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
125
|
+
{header.isPlaceholder ? null : column.columnDefType === 'display' ? (
|
|
126
|
+
headerElement
|
|
127
|
+
) : (
|
|
132
128
|
<Box
|
|
133
|
-
{...column.getSortByToggleProps()}
|
|
134
129
|
sx={{
|
|
135
|
-
alignItems: '
|
|
130
|
+
alignItems: 'flex-start',
|
|
136
131
|
display: 'flex',
|
|
137
|
-
|
|
138
|
-
|
|
132
|
+
justifyContent:
|
|
133
|
+
column.columnDefType === 'group' ? 'center' : 'space-between',
|
|
134
|
+
width: '100%',
|
|
139
135
|
}}
|
|
140
|
-
title={undefined}
|
|
141
136
|
>
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
137
|
+
<Box
|
|
138
|
+
{...column.getToggleSortingProps()}
|
|
139
|
+
sx={{
|
|
140
|
+
alignItems: 'center',
|
|
141
|
+
cursor:
|
|
142
|
+
column.getCanSort() && column.columnDefType !== 'group'
|
|
143
|
+
? 'pointer'
|
|
144
|
+
: undefined,
|
|
145
|
+
display: 'flex',
|
|
146
|
+
flexWrap: 'nowrap',
|
|
147
|
+
whiteSpace: column.header.length < 15 ? 'nowrap' : 'normal',
|
|
148
|
+
}}
|
|
149
|
+
title={undefined}
|
|
150
|
+
>
|
|
151
|
+
{headerElement}
|
|
152
|
+
{column.columnDefType !== 'group' && column.getCanSort() && (
|
|
153
|
+
<Tooltip arrow placement="top" title={sortTooltip}>
|
|
154
|
+
<TableSortLabel
|
|
155
|
+
aria-label={sortTooltip}
|
|
156
|
+
active={!!column.getIsSorted()}
|
|
157
|
+
direction={
|
|
158
|
+
column.getIsSorted()
|
|
159
|
+
? (column.getIsSorted() as 'asc' | 'desc')
|
|
160
|
+
: undefined
|
|
161
|
+
}
|
|
162
|
+
/>
|
|
163
|
+
</Tooltip>
|
|
164
|
+
)}
|
|
165
|
+
{column.columnDefType !== 'group' &&
|
|
166
|
+
enableColumnFilters &&
|
|
167
|
+
!!column.getCanColumnFilter() && (
|
|
168
|
+
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
169
|
+
<IconButton
|
|
170
|
+
disableRipple
|
|
171
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
|
172
|
+
event.stopPropagation();
|
|
173
|
+
setShowFilters(!showFilters);
|
|
174
|
+
}}
|
|
175
|
+
size="small"
|
|
176
|
+
sx={{
|
|
177
|
+
m: 0,
|
|
178
|
+
opacity: !!column.getColumnFilterValue() ? 0.8 : 0,
|
|
179
|
+
p: '2px',
|
|
180
|
+
transition: 'all 0.2s ease-in-out',
|
|
181
|
+
'&:hover': {
|
|
182
|
+
backgroundColor: 'transparent',
|
|
183
|
+
opacity: 0.8,
|
|
184
|
+
},
|
|
185
|
+
}}
|
|
186
|
+
>
|
|
187
|
+
{showFilters && !column.getColumnFilterValue() ? (
|
|
188
|
+
<FilterAltOff fontSize="small" />
|
|
189
|
+
) : (
|
|
190
|
+
<FilterAltIcon fontSize="small" />
|
|
191
|
+
)}
|
|
192
|
+
</IconButton>
|
|
193
|
+
</Tooltip>
|
|
194
|
+
)}
|
|
195
|
+
</Box>
|
|
196
|
+
<Box
|
|
197
|
+
sx={{ alignItems: 'center', display: 'flex', flexWrap: 'nowrap' }}
|
|
198
|
+
>
|
|
199
|
+
{(enableColumnActions || column.enableColumnActions) &&
|
|
200
|
+
column.enableColumnActions !== false &&
|
|
201
|
+
column.columnDefType !== 'group' && (
|
|
202
|
+
<MRT_ToggleColumnActionMenuButton
|
|
203
|
+
header={header}
|
|
204
|
+
tableInstance={tableInstance}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
{enableColumnResizing && column.columnDefType !== 'group' && (
|
|
208
|
+
<Divider
|
|
209
|
+
flexItem
|
|
210
|
+
orientation="vertical"
|
|
211
|
+
onDoubleClick={() => header.resetSize()}
|
|
212
|
+
sx={(theme: Theme) => ({
|
|
213
|
+
borderRightWidth: '2px',
|
|
214
|
+
borderRadius: '2px',
|
|
215
|
+
maxHeight: '2rem',
|
|
216
|
+
cursor: 'col-resize',
|
|
217
|
+
userSelect: 'none',
|
|
218
|
+
touchAction: 'none',
|
|
219
|
+
'&:active': {
|
|
220
|
+
backgroundColor: theme.palette.secondary.dark,
|
|
221
|
+
opacity: 1,
|
|
169
222
|
},
|
|
170
|
-
}}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
{!disableColumnActions &&
|
|
183
|
-
!column.disableColumnActions &&
|
|
184
|
-
!isParentHeader && (
|
|
185
|
-
<MRT_ToggleColumnActionMenuButton column={column} />
|
|
223
|
+
})}
|
|
224
|
+
{...(header.getResizerProps((props: ColumnResizerProps) => ({
|
|
225
|
+
...props,
|
|
226
|
+
style: {
|
|
227
|
+
transform: column.getIsResizing()
|
|
228
|
+
? `translateX(${
|
|
229
|
+
getState().columnSizingInfo.deltaOffset
|
|
230
|
+
}px)`
|
|
231
|
+
: '',
|
|
232
|
+
},
|
|
233
|
+
})) as any)}
|
|
234
|
+
/>
|
|
186
235
|
)}
|
|
187
|
-
|
|
188
|
-
<Divider
|
|
189
|
-
flexItem
|
|
190
|
-
orientation="vertical"
|
|
191
|
-
onDoubleClick={() => tableInstance.resetResizing()}
|
|
192
|
-
{...column.getResizerProps()}
|
|
193
|
-
sx={{
|
|
194
|
-
borderRightWidth: '2px',
|
|
195
|
-
borderRadius: '2px',
|
|
196
|
-
maxHeight: '2rem',
|
|
197
|
-
}}
|
|
198
|
-
/>
|
|
199
|
-
)}
|
|
236
|
+
</Box>
|
|
200
237
|
</Box>
|
|
201
|
-
</Box>
|
|
202
|
-
{!disableFilters && column.canFilter && (
|
|
203
|
-
<Collapse in={tableInstance.state.showFilters}>
|
|
204
|
-
<MRT_FilterTextField column={column} />
|
|
205
|
-
</Collapse>
|
|
206
238
|
)}
|
|
239
|
+
{column.columnDefType === 'data' &&
|
|
240
|
+
enableColumnFilters &&
|
|
241
|
+
column.getCanColumnFilter() && (
|
|
242
|
+
<Collapse in={showFilters}>
|
|
243
|
+
<MRT_FilterTextField
|
|
244
|
+
header={header}
|
|
245
|
+
tableInstance={tableInstance}
|
|
246
|
+
/>
|
|
247
|
+
</Collapse>
|
|
248
|
+
)}
|
|
207
249
|
</TableCell>
|
|
208
250
|
);
|
|
209
251
|
};
|
|
@@ -1,125 +1,37 @@
|
|
|
1
|
-
import React, { FC
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
MRT_TableHeadCell,
|
|
6
|
-
} from './MRT_TableHeadCell';
|
|
7
|
-
import { useMRT } from '../useMRT';
|
|
8
|
-
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
9
|
-
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
10
|
-
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
11
|
-
import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
|
|
12
|
-
import type { MRT_HeaderGroup } from '..';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { TableRow } from '@mui/material';
|
|
3
|
+
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
+
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
|
13
5
|
|
|
14
6
|
interface Props {
|
|
15
7
|
headerGroup: MRT_HeaderGroup;
|
|
8
|
+
tableInstance: MRT_TableInstance;
|
|
16
9
|
}
|
|
17
10
|
|
|
18
|
-
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
11
|
+
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
19
12
|
const {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
disableSelectAll,
|
|
23
|
-
enableRowActions,
|
|
24
|
-
enableRowEditing,
|
|
25
|
-
enableRowNumbers,
|
|
26
|
-
enableSelection,
|
|
27
|
-
muiTableHeadRowProps,
|
|
28
|
-
positionActionsColumn,
|
|
29
|
-
renderDetailPanel,
|
|
30
|
-
tableInstance,
|
|
31
|
-
} = useMRT();
|
|
32
|
-
|
|
33
|
-
const isParentHeader = useMemo(
|
|
34
|
-
() => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
|
|
35
|
-
[headerGroup.headers],
|
|
36
|
-
);
|
|
13
|
+
options: { muiTableHeadRowProps },
|
|
14
|
+
} = tableInstance;
|
|
37
15
|
|
|
38
16
|
const mTableHeadRowProps =
|
|
39
17
|
muiTableHeadRowProps instanceof Function
|
|
40
|
-
? muiTableHeadRowProps(headerGroup)
|
|
18
|
+
? muiTableHeadRowProps({ headerGroup, tableInstance })
|
|
41
19
|
: muiTableHeadRowProps;
|
|
42
20
|
|
|
43
21
|
const tableRowProps = {
|
|
22
|
+
...headerGroup?.getHeaderGroupProps(),
|
|
44
23
|
...mTableHeadRowProps,
|
|
45
|
-
...headerGroup.getHeaderGroupProps(),
|
|
46
|
-
style: {
|
|
47
|
-
...headerGroup.getHeaderGroupProps().style,
|
|
48
|
-
...mTableHeadRowProps?.style,
|
|
49
|
-
},
|
|
50
24
|
};
|
|
51
25
|
|
|
52
26
|
return (
|
|
53
27
|
<TableRow {...tableRowProps}>
|
|
54
|
-
{(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
))}
|
|
61
|
-
{anyRowsCanExpand || renderDetailPanel ? (
|
|
62
|
-
!disableExpandAll && !isParentHeader ? (
|
|
63
|
-
<TableCell
|
|
64
|
-
size="small"
|
|
65
|
-
{...tableInstance.getToggleAllRowsExpandedProps()}
|
|
66
|
-
sx={{
|
|
67
|
-
...commonTableHeadCellStyles(tableInstance.state.densePadding),
|
|
68
|
-
width: '3rem',
|
|
69
|
-
maxWidth: '3rem',
|
|
70
|
-
textAlign: 'center',
|
|
71
|
-
}}
|
|
72
|
-
>
|
|
73
|
-
<MRT_ExpandAllButton />
|
|
74
|
-
</TableCell>
|
|
75
|
-
) : (
|
|
76
|
-
<MRT_TableSpacerCell
|
|
77
|
-
width={`${
|
|
78
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
79
|
-
}rem`}
|
|
80
|
-
/>
|
|
81
|
-
)
|
|
82
|
-
) : null}
|
|
83
|
-
{enableSelection ? (
|
|
84
|
-
!isParentHeader && !disableSelectAll ? (
|
|
85
|
-
<TableCell
|
|
86
|
-
sx={{
|
|
87
|
-
...commonTableHeadCellStyles(tableInstance.state.densePadding),
|
|
88
|
-
maxWidth: '3rem',
|
|
89
|
-
width: '3rem',
|
|
90
|
-
textAlign: 'center',
|
|
91
|
-
}}
|
|
92
|
-
>
|
|
93
|
-
<MRT_SelectCheckbox selectAll />
|
|
94
|
-
</TableCell>
|
|
95
|
-
) : (
|
|
96
|
-
<MRT_TableSpacerCell width="1rem" />
|
|
97
|
-
)
|
|
98
|
-
) : null}
|
|
99
|
-
{enableRowNumbers &&
|
|
100
|
-
(isParentHeader ? (
|
|
101
|
-
<MRT_TableSpacerCell />
|
|
102
|
-
) : (
|
|
103
|
-
<TableCell
|
|
104
|
-
sx={{
|
|
105
|
-
...commonTableHeadCellStyles(tableInstance.state.densePadding),
|
|
106
|
-
width: '2rem',
|
|
107
|
-
maxWidth: '2rem',
|
|
108
|
-
}}
|
|
109
|
-
>
|
|
110
|
-
#
|
|
111
|
-
</TableCell>
|
|
112
|
-
))}
|
|
113
|
-
{headerGroup.headers.map((column: MRT_HeaderGroup) => (
|
|
114
|
-
<MRT_TableHeadCell key={column.getHeaderProps().key} column={column} />
|
|
28
|
+
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
29
|
+
<MRT_TableHeadCell
|
|
30
|
+
header={header}
|
|
31
|
+
key={header.id || index}
|
|
32
|
+
tableInstance={tableInstance}
|
|
33
|
+
/>
|
|
115
34
|
))}
|
|
116
|
-
{(enableRowActions || enableRowEditing) &&
|
|
117
|
-
positionActionsColumn === 'last' &&
|
|
118
|
-
(isParentHeader ? (
|
|
119
|
-
<MRT_TableSpacerCell />
|
|
120
|
-
) : (
|
|
121
|
-
<MRT_TableHeadCellActions />
|
|
122
|
-
))}
|
|
123
35
|
</TableRow>
|
|
124
36
|
);
|
|
125
37
|
};
|
package/src/icons.ts
CHANGED
|
@@ -3,7 +3,6 @@ import CancelIcon from '@mui/icons-material/Cancel';
|
|
|
3
3
|
import CheckBoxIcon from '@mui/icons-material/CheckBox';
|
|
4
4
|
import ClearAllIcon from '@mui/icons-material/ClearAll';
|
|
5
5
|
import CloseIcon from '@mui/icons-material/Close';
|
|
6
|
-
import ContentCopyIcon from '@mui/icons-material/ContentCopy';
|
|
7
6
|
import DensityMediumIcon from '@mui/icons-material/DensityMedium';
|
|
8
7
|
import DensitySmallIcon from '@mui/icons-material/DensitySmall';
|
|
9
8
|
import DoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
|
@@ -19,6 +18,7 @@ import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
|
|
19
18
|
import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
|
20
19
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
21
20
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
21
|
+
import PushPinIcon from '@mui/icons-material/PushPin';
|
|
22
22
|
import SaveIcon from '@mui/icons-material/Save';
|
|
23
23
|
import SearchIcon from '@mui/icons-material/Search';
|
|
24
24
|
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
@@ -32,7 +32,6 @@ export interface MRT_Icons {
|
|
|
32
32
|
CheckBoxIcon: any;
|
|
33
33
|
ClearAllIcon: any;
|
|
34
34
|
CloseIcon: any;
|
|
35
|
-
ContentCopyIcon: any;
|
|
36
35
|
DensityMediumIcon: any;
|
|
37
36
|
DensitySmallIcon: any;
|
|
38
37
|
DoubleArrowDownIcon: any;
|
|
@@ -48,6 +47,7 @@ export interface MRT_Icons {
|
|
|
48
47
|
FullscreenIcon: any;
|
|
49
48
|
MoreHorizIcon: any;
|
|
50
49
|
MoreVertIcon: any;
|
|
50
|
+
PushPinIcon: any;
|
|
51
51
|
SaveIcon: any;
|
|
52
52
|
SearchIcon: any;
|
|
53
53
|
SearchOffIcon: any;
|
|
@@ -62,7 +62,6 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
62
62
|
CheckBoxIcon,
|
|
63
63
|
ClearAllIcon,
|
|
64
64
|
CloseIcon,
|
|
65
|
-
ContentCopyIcon,
|
|
66
65
|
DensityMediumIcon,
|
|
67
66
|
DensitySmallIcon,
|
|
68
67
|
DoubleArrowDownIcon,
|
|
@@ -78,6 +77,7 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
78
77
|
FullscreenIcon,
|
|
79
78
|
MoreHorizIcon,
|
|
80
79
|
MoreVertIcon,
|
|
80
|
+
PushPinIcon,
|
|
81
81
|
SaveIcon,
|
|
82
82
|
SearchIcon,
|
|
83
83
|
SearchOffIcon,
|
|
@@ -1,56 +1,55 @@
|
|
|
1
|
-
import React, { ChangeEvent, FC } from 'react';
|
|
1
|
+
import React, { ChangeEvent, FC, MouseEvent } from 'react';
|
|
2
2
|
import { TextField } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_Cell } from '..';
|
|
3
|
+
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
5
4
|
|
|
6
5
|
interface Props {
|
|
7
6
|
cell: MRT_Cell;
|
|
7
|
+
tableInstance: MRT_TableInstance;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
10
|
+
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
11
11
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
} = useMRT();
|
|
12
|
+
getState,
|
|
13
|
+
options: { enableRowEditing, muiTableBodyCellEditTextFieldProps },
|
|
14
|
+
} = tableInstance;
|
|
15
|
+
|
|
16
|
+
const { column, row } = cell;
|
|
18
17
|
|
|
19
18
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
20
|
-
if (currentEditingRow) {
|
|
21
|
-
|
|
22
|
-
setCurrentEditingRow({
|
|
23
|
-
|
|
24
|
-
});
|
|
19
|
+
if (getState().currentEditingRow) {
|
|
20
|
+
row.values[column.id] = event.target.value;
|
|
21
|
+
// setCurrentEditingRow({
|
|
22
|
+
// ...getState().currentEditingRow,
|
|
23
|
+
// });
|
|
25
24
|
}
|
|
26
|
-
|
|
25
|
+
column.onCellEditChange?.({ event, cell, tableInstance });
|
|
27
26
|
};
|
|
28
27
|
|
|
29
28
|
const mTableBodyCellEditTextFieldProps =
|
|
30
29
|
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
31
|
-
? muiTableBodyCellEditTextFieldProps(cell)
|
|
30
|
+
? muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
32
31
|
: muiTableBodyCellEditTextFieldProps;
|
|
33
32
|
|
|
34
33
|
const mcTableBodyCellEditTextFieldProps =
|
|
35
|
-
|
|
36
|
-
?
|
|
37
|
-
:
|
|
34
|
+
column.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
35
|
+
? column.muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
36
|
+
: column.muiTableBodyCellEditTextFieldProps;
|
|
38
37
|
|
|
39
38
|
const textFieldProps = {
|
|
40
39
|
...mTableBodyCellEditTextFieldProps,
|
|
41
40
|
...mcTableBodyCellEditTextFieldProps,
|
|
42
41
|
};
|
|
43
42
|
|
|
44
|
-
if (
|
|
45
|
-
return <>{
|
|
43
|
+
if (enableRowEditing && column.enableEditing !== false && column.Edit) {
|
|
44
|
+
return <>{column.Edit?.({ cell, tableInstance })}</>;
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
return (
|
|
49
48
|
<TextField
|
|
50
49
|
margin="dense"
|
|
51
50
|
onChange={handleChange}
|
|
52
|
-
onClick={(e) => e.stopPropagation()}
|
|
53
|
-
placeholder={
|
|
51
|
+
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
52
|
+
placeholder={column.header}
|
|
54
53
|
value={cell.value}
|
|
55
54
|
variant="standard"
|
|
56
55
|
{...textFieldProps}
|