material-react-table 0.7.5 → 0.8.0-alpha.2
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 +16 -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_ColumnPinningButtons.d.ts +8 -0
- 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 +7 -2
- package/dist/material-react-table.cjs.development.js +451 -418
- 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 +454 -421
- 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 +21 -25
- package/src/MaterialReactTable.tsx +20 -24
- package/src/body/MRT_TableBody.tsx +3 -11
- package/src/body/MRT_TableBodyCell.tsx +103 -52
- package/src/body/MRT_TableBodyRow.tsx +21 -30
- package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +22 -18
- package/src/buttons/MRT_ExpandButton.tsx +27 -21
- 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 +15 -15
- package/src/footer/MRT_TableFooterRow.tsx +6 -8
- package/src/head/MRT_TableHead.tsx +5 -16
- package/src/head/MRT_TableHeadCell.tsx +116 -49
- package/src/head/MRT_TableHeadRow.tsx +8 -15
- package/src/inputs/MRT_EditCellTextField.tsx +3 -3
- package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/inputs/MRT_FilterTextField.tsx +76 -41
- package/src/inputs/MRT_SelectCheckbox.tsx +15 -17
- package/src/localization.ts +15 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +13 -12
- package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +16 -6
- package/src/table/MRT_Table.tsx +8 -19
- package/src/table/MRT_TableContainer.tsx +8 -69
- package/src/table/MRT_TableRoot.tsx +44 -52
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import React, { FC, MouseEvent } from 'react';
|
|
1
|
+
import React, { FC, MouseEvent, ReactNode } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
Box,
|
|
4
|
+
Collapse,
|
|
5
|
+
Divider,
|
|
6
|
+
IconButton,
|
|
3
7
|
TableCell,
|
|
4
8
|
TableSortLabel,
|
|
5
|
-
|
|
6
|
-
Collapse,
|
|
9
|
+
Theme,
|
|
7
10
|
Tooltip,
|
|
8
|
-
Box,
|
|
9
|
-
IconButton,
|
|
10
11
|
alpha,
|
|
11
|
-
|
|
12
|
+
lighten,
|
|
12
13
|
} from '@mui/material';
|
|
13
14
|
import { MRT_FilterTextField } from '../inputs/MRT_FilterTextField';
|
|
14
15
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
15
16
|
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
16
|
-
import
|
|
17
|
+
import MRT_FilterRangeFields from '../inputs/MRT_FilterRangeFields';
|
|
18
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
17
19
|
|
|
18
20
|
interface Props {
|
|
19
21
|
header: MRT_Header;
|
|
@@ -34,7 +36,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
34
36
|
setShowFilters,
|
|
35
37
|
} = tableInstance;
|
|
36
38
|
|
|
37
|
-
const { isDensePadding, showFilters } = getState();
|
|
39
|
+
const { currentFilterFns, isDensePadding, showFilters } = getState();
|
|
38
40
|
|
|
39
41
|
const { column } = header;
|
|
40
42
|
|
|
@@ -49,22 +51,27 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
49
51
|
: column.muiTableHeadCellProps;
|
|
50
52
|
|
|
51
53
|
const tableCellProps = {
|
|
52
|
-
...header.getHeaderProps(),
|
|
53
54
|
...mTableHeadCellProps,
|
|
54
55
|
...mcTableHeadCellProps,
|
|
55
56
|
};
|
|
56
57
|
|
|
57
58
|
const sortTooltip = !!column.getIsSorted()
|
|
58
59
|
? column.getIsSorted() === 'desc'
|
|
59
|
-
? localization.sortedByColumnDesc.replace(
|
|
60
|
-
|
|
60
|
+
? localization.sortedByColumnDesc.replace(
|
|
61
|
+
'{column}',
|
|
62
|
+
column.columnDef.header,
|
|
63
|
+
)
|
|
64
|
+
: localization.sortedByColumnAsc.replace(
|
|
65
|
+
'{column}',
|
|
66
|
+
column.columnDef.header,
|
|
67
|
+
)
|
|
61
68
|
: localization.unsorted;
|
|
62
69
|
|
|
63
70
|
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
64
71
|
|
|
65
|
-
const filterTooltip = !!column.
|
|
72
|
+
const filterTooltip = !!column.getFilterValue()
|
|
66
73
|
? localization.filteringByColumn
|
|
67
|
-
.replace('{column}', String(column.header))
|
|
74
|
+
.replace('{column}', String(column.columnDef.header))
|
|
68
75
|
.replace(
|
|
69
76
|
'{filterType}',
|
|
70
77
|
filterFn instanceof Function
|
|
@@ -74,31 +81,69 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
74
81
|
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
75
82
|
],
|
|
76
83
|
)
|
|
77
|
-
.replace(
|
|
84
|
+
.replace(
|
|
85
|
+
'{filterValue}',
|
|
86
|
+
`"${
|
|
87
|
+
Array.isArray(column.getFilterValue())
|
|
88
|
+
? (column.getFilterValue() as [string, string]).join(
|
|
89
|
+
`" ${localization.and} "`,
|
|
90
|
+
)
|
|
91
|
+
: (column.getFilterValue() as string)
|
|
92
|
+
}"`,
|
|
93
|
+
)
|
|
78
94
|
.replace('" "', '')
|
|
79
95
|
: localization.showHideFilters;
|
|
80
96
|
|
|
81
|
-
const headerElement =
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
97
|
+
const headerElement = (column.columnDef?.Header?.({
|
|
98
|
+
header,
|
|
99
|
+
tableInstance,
|
|
100
|
+
}) ?? header.renderHeader()) as ReactNode;
|
|
101
|
+
|
|
102
|
+
const getIsLastLeftPinnedColumn = () => {
|
|
103
|
+
return (
|
|
104
|
+
column.getIsPinned() === 'left' &&
|
|
105
|
+
tableInstance.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
|
106
|
+
);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const getIsFirstRightPinnedColumn = () => {
|
|
110
|
+
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const getTotalRight = () => {
|
|
114
|
+
return (
|
|
115
|
+
(tableInstance.getRightLeafHeaders().length -
|
|
116
|
+
1 -
|
|
117
|
+
column.getPinnedIndex()) *
|
|
118
|
+
150
|
|
119
|
+
);
|
|
120
|
+
};
|
|
86
121
|
|
|
87
122
|
return (
|
|
88
123
|
<TableCell
|
|
89
124
|
align={column.columnDefType === 'group' ? 'center' : 'left'}
|
|
125
|
+
colSpan={header.colSpan}
|
|
90
126
|
{...tableCellProps}
|
|
91
|
-
//@ts-ignore
|
|
92
127
|
sx={(theme: Theme) => ({
|
|
93
|
-
backgroundColor:
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
128
|
+
backgroundColor:
|
|
129
|
+
column.getIsPinned() && column.columnDefType !== 'group'
|
|
130
|
+
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
131
|
+
: 'inherit',
|
|
132
|
+
backgroundImage: 'inherit',
|
|
133
|
+
boxShadow: getIsLastLeftPinnedColumn()
|
|
134
|
+
? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
135
|
+
: getIsFirstRightPinnedColumn()
|
|
136
|
+
? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
137
|
+
: undefined,
|
|
98
138
|
fontWeight: 'bold',
|
|
99
139
|
height: '100%',
|
|
100
|
-
|
|
101
|
-
|
|
140
|
+
left:
|
|
141
|
+
column.getIsPinned() === 'left'
|
|
142
|
+
? `${column.getStart('left')}px`
|
|
143
|
+
: undefined,
|
|
144
|
+
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
145
|
+
minWidth: `max(${column.getSize()}px, ${column.minSize}px)`,
|
|
146
|
+
overflow: 'visible',
|
|
102
147
|
p: isDensePadding
|
|
103
148
|
? column.columnDefType === 'display'
|
|
104
149
|
? '0 0.5rem'
|
|
@@ -106,20 +151,28 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
106
151
|
: column.columnDefType === 'display'
|
|
107
152
|
? '0.5rem 0.75rem'
|
|
108
153
|
: '1rem',
|
|
154
|
+
pb: column.columnDefType === 'display' ? 0 : undefined,
|
|
155
|
+
position:
|
|
156
|
+
column.getIsPinned() && column.columnDefType !== 'group'
|
|
157
|
+
? 'sticky'
|
|
158
|
+
: undefined,
|
|
109
159
|
pt:
|
|
110
160
|
column.columnDefType === 'display'
|
|
111
161
|
? 0
|
|
112
162
|
: isDensePadding
|
|
113
163
|
? '0.75rem'
|
|
114
164
|
: '1.25rem',
|
|
115
|
-
|
|
116
|
-
|
|
165
|
+
right:
|
|
166
|
+
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
117
167
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
118
168
|
verticalAlign: 'text-top',
|
|
119
|
-
width: header.
|
|
120
|
-
zIndex: column.getIsResizing()
|
|
121
|
-
|
|
122
|
-
|
|
169
|
+
width: header.getSize(),
|
|
170
|
+
zIndex: column.getIsResizing()
|
|
171
|
+
? 3
|
|
172
|
+
: column.getIsPinned() && column.columnDefType !== 'group'
|
|
173
|
+
? 2
|
|
174
|
+
: 1,
|
|
175
|
+
...(tableCellProps?.sx as any),
|
|
123
176
|
})}
|
|
124
177
|
>
|
|
125
178
|
{header.isPlaceholder ? null : column.columnDefType === 'display' ? (
|
|
@@ -144,7 +197,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
144
197
|
: undefined,
|
|
145
198
|
display: 'flex',
|
|
146
199
|
flexWrap: 'nowrap',
|
|
147
|
-
whiteSpace:
|
|
200
|
+
whiteSpace:
|
|
201
|
+
(column.columnDef.header?.length ?? 0) < 24
|
|
202
|
+
? 'nowrap'
|
|
203
|
+
: 'normal',
|
|
148
204
|
}}
|
|
149
205
|
>
|
|
150
206
|
{headerElement}
|
|
@@ -163,7 +219,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
163
219
|
)}
|
|
164
220
|
{column.columnDefType === 'data' &&
|
|
165
221
|
enableColumnFilters &&
|
|
166
|
-
!!column.
|
|
222
|
+
!!column.getCanFilter() && (
|
|
167
223
|
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
168
224
|
<IconButton
|
|
169
225
|
disableRipple
|
|
@@ -174,7 +230,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
174
230
|
size="small"
|
|
175
231
|
sx={{
|
|
176
232
|
m: 0,
|
|
177
|
-
opacity: !!column.
|
|
233
|
+
opacity: !!column.getFilterValue() ? 0.8 : 0,
|
|
178
234
|
p: '2px',
|
|
179
235
|
transition: 'all 0.2s ease-in-out',
|
|
180
236
|
'&:hover': {
|
|
@@ -183,7 +239,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
183
239
|
},
|
|
184
240
|
}}
|
|
185
241
|
>
|
|
186
|
-
{showFilters && !column.
|
|
242
|
+
{showFilters && !column.getFilterValue() ? (
|
|
187
243
|
<FilterAltOff />
|
|
188
244
|
) : (
|
|
189
245
|
<FilterAltIcon />
|
|
@@ -204,7 +260,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
204
260
|
<Divider
|
|
205
261
|
flexItem
|
|
206
262
|
orientation="vertical"
|
|
207
|
-
onDoubleClick={() =>
|
|
263
|
+
onDoubleClick={() => column.resetSize()}
|
|
208
264
|
sx={(theme: Theme) => ({
|
|
209
265
|
borderRadius: '2px',
|
|
210
266
|
borderRightWidth: '2px',
|
|
@@ -225,21 +281,32 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
225
281
|
opacity: 1,
|
|
226
282
|
},
|
|
227
283
|
})}
|
|
228
|
-
{...
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
284
|
+
{...{
|
|
285
|
+
onMouseDown: header.getResizeHandler,
|
|
286
|
+
onTouchStart: header.getResizeHandler,
|
|
287
|
+
}}
|
|
288
|
+
style={{
|
|
289
|
+
transform: column.getIsResizing()
|
|
290
|
+
? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
|
|
291
|
+
: 'none',
|
|
292
|
+
}}
|
|
236
293
|
/>
|
|
237
294
|
)}
|
|
238
295
|
</Box>
|
|
239
296
|
)}
|
|
240
|
-
{column.columnDefType === 'data' && column.
|
|
241
|
-
<Collapse in={showFilters}>
|
|
242
|
-
|
|
297
|
+
{column.columnDefType === 'data' && column.getCanFilter() && (
|
|
298
|
+
<Collapse in={showFilters} mountOnEnter unmountOnExit>
|
|
299
|
+
{currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
|
|
300
|
+
<MRT_FilterRangeFields
|
|
301
|
+
header={header}
|
|
302
|
+
tableInstance={tableInstance}
|
|
303
|
+
/>
|
|
304
|
+
) : (
|
|
305
|
+
<MRT_FilterTextField
|
|
306
|
+
header={header}
|
|
307
|
+
tableInstance={tableInstance}
|
|
308
|
+
/>
|
|
309
|
+
)}
|
|
243
310
|
</Collapse>
|
|
244
311
|
)}
|
|
245
312
|
</TableCell>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import { alpha, TableRow } from '@mui/material';
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { alpha, lighten, TableRow } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
4
|
import type { MRT_Header, MRT_HeaderGroup, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
@@ -13,26 +13,19 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
|
13
13
|
options: { muiTableHeadRowProps },
|
|
14
14
|
} = tableInstance;
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const tableRowProps =
|
|
17
17
|
muiTableHeadRowProps instanceof Function
|
|
18
18
|
? muiTableHeadRowProps({ headerGroup, tableInstance })
|
|
19
19
|
: muiTableHeadRowProps;
|
|
20
20
|
|
|
21
|
-
const tableRowProps = {
|
|
22
|
-
...headerGroup?.getHeaderGroupProps(),
|
|
23
|
-
...mTableHeadRowProps,
|
|
24
|
-
};
|
|
25
|
-
|
|
26
21
|
return (
|
|
27
22
|
<TableRow
|
|
28
23
|
{...tableRowProps}
|
|
29
|
-
sx={(theme) =>
|
|
30
|
-
(
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
} as CSSProperties)
|
|
35
|
-
}
|
|
24
|
+
sx={(theme) => ({
|
|
25
|
+
boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
26
|
+
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
27
|
+
...(tableRowProps?.sx as any),
|
|
28
|
+
})}
|
|
36
29
|
>
|
|
37
30
|
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
38
31
|
<MRT_TableHeadCell
|
|
@@ -27,7 +27,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
27
27
|
setCurrentEditingRow,
|
|
28
28
|
} = tableInstance;
|
|
29
29
|
|
|
30
|
-
const [value, setValue] = useState(cell.
|
|
30
|
+
const [value, setValue] = useState(cell.getValue());
|
|
31
31
|
|
|
32
32
|
const { column, row } = cell;
|
|
33
33
|
|
|
@@ -39,7 +39,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
39
39
|
|
|
40
40
|
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
41
41
|
if (getState().currentEditingRow) {
|
|
42
|
-
row.
|
|
42
|
+
row._valuesCache[column.id] = value;
|
|
43
43
|
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
44
44
|
}
|
|
45
45
|
setCurrentEditingCell(null);
|
|
@@ -73,7 +73,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
73
73
|
onBlur={handleBlur}
|
|
74
74
|
onChange={handleChange}
|
|
75
75
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
76
|
-
placeholder={column.header}
|
|
76
|
+
placeholder={column.columnDef.header}
|
|
77
77
|
value={value}
|
|
78
78
|
variant="standard"
|
|
79
79
|
{...textFieldProps}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { MRT_FilterTextField } from './MRT_FilterTextField';
|
|
4
|
+
import { MRT_Header, MRT_TableInstance } from '..';
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
header: MRT_Header;
|
|
8
|
+
tableInstance: MRT_TableInstance;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const MRT_FilterRangeFields: FC<Props> = ({ header, tableInstance }) => {
|
|
12
|
+
const {
|
|
13
|
+
options: { localization },
|
|
14
|
+
} = tableInstance;
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<Box sx={{ display: 'grid', gridTemplateColumns: '6fr auto 5fr' }}>
|
|
18
|
+
<MRT_FilterTextField
|
|
19
|
+
header={header}
|
|
20
|
+
inputIndex={0}
|
|
21
|
+
tableInstance={tableInstance}
|
|
22
|
+
/>
|
|
23
|
+
<Box
|
|
24
|
+
sx={{
|
|
25
|
+
width: '100%',
|
|
26
|
+
minWidth: '5ch',
|
|
27
|
+
textAlign: 'center',
|
|
28
|
+
}}
|
|
29
|
+
>
|
|
30
|
+
{localization.to}
|
|
31
|
+
</Box>
|
|
32
|
+
<MRT_FilterTextField
|
|
33
|
+
header={header}
|
|
34
|
+
inputIndex={1}
|
|
35
|
+
tableInstance={tableInstance}
|
|
36
|
+
/>
|
|
37
|
+
</Box>
|
|
38
|
+
);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export default MRT_FilterRangeFields;
|
|
@@ -21,10 +21,15 @@ import { MRT_FILTER_OPTION } from '../enums';
|
|
|
21
21
|
|
|
22
22
|
interface Props {
|
|
23
23
|
header: MRT_Header;
|
|
24
|
+
inputIndex?: number;
|
|
24
25
|
tableInstance: MRT_TableInstance;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
export const MRT_FilterTextField: FC<Props> = ({
|
|
28
|
+
export const MRT_FilterTextField: FC<Props> = ({
|
|
29
|
+
header,
|
|
30
|
+
inputIndex,
|
|
31
|
+
tableInstance,
|
|
32
|
+
}) => {
|
|
28
33
|
const {
|
|
29
34
|
getState,
|
|
30
35
|
options: {
|
|
@@ -57,14 +62,22 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
57
62
|
...mcTableHeadCellFilterTextFieldProps,
|
|
58
63
|
} as TextFieldProps;
|
|
59
64
|
|
|
60
|
-
const [filterValue, setFilterValue] = useState<string>(
|
|
61
|
-
|
|
65
|
+
const [filterValue, setFilterValue] = useState<string>(() =>
|
|
66
|
+
inputIndex !== undefined
|
|
67
|
+
? (column.getFilterValue() as [string, string])?.[inputIndex] ?? ''
|
|
68
|
+
: (column.getFilterValue() as string) ?? '',
|
|
62
69
|
);
|
|
63
70
|
|
|
64
|
-
const
|
|
71
|
+
const handleChangeDebounced = useCallback(
|
|
65
72
|
debounce(
|
|
66
73
|
(event: ChangeEvent<HTMLInputElement>) =>
|
|
67
|
-
|
|
74
|
+
inputIndex !== undefined
|
|
75
|
+
? column.setFilterValue((old: [string, string]) => {
|
|
76
|
+
const newFilterValues = old ?? ['', ''];
|
|
77
|
+
newFilterValues[inputIndex] = event.target.value;
|
|
78
|
+
return newFilterValues;
|
|
79
|
+
})
|
|
80
|
+
: column.setFilterValue(event.target.value ?? undefined),
|
|
68
81
|
150,
|
|
69
82
|
),
|
|
70
83
|
[],
|
|
@@ -76,15 +89,23 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
76
89
|
|
|
77
90
|
const handleClear = () => {
|
|
78
91
|
setFilterValue('');
|
|
79
|
-
|
|
92
|
+
if (inputIndex !== undefined) {
|
|
93
|
+
column.setFilterValue((old: [string | undefined, string | undefined]) => {
|
|
94
|
+
const newFilterValues = old ?? ['', ''];
|
|
95
|
+
newFilterValues[inputIndex] = undefined;
|
|
96
|
+
return newFilterValues;
|
|
97
|
+
});
|
|
98
|
+
} else {
|
|
99
|
+
column.setFilterValue(undefined);
|
|
100
|
+
}
|
|
80
101
|
};
|
|
81
102
|
|
|
82
103
|
const handleClearFilterChip = () => {
|
|
83
104
|
setFilterValue('');
|
|
84
|
-
column.
|
|
105
|
+
column.setFilterValue(undefined);
|
|
85
106
|
setCurrentFilterFns((prev) => ({
|
|
86
107
|
...prev,
|
|
87
|
-
[header.id]: MRT_FILTER_OPTION.
|
|
108
|
+
[header.id]: MRT_FILTER_OPTION.FUZZY,
|
|
88
109
|
}));
|
|
89
110
|
};
|
|
90
111
|
|
|
@@ -92,7 +113,9 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
92
113
|
return <>{column.Filter?.({ header, tableInstance })}</>;
|
|
93
114
|
}
|
|
94
115
|
|
|
95
|
-
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field
|
|
116
|
+
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field${
|
|
117
|
+
inputIndex ?? ''
|
|
118
|
+
}`;
|
|
96
119
|
const filterFn = currentFilterFns?.[header.id];
|
|
97
120
|
const isSelectFilter = !!column.filterSelectOptions;
|
|
98
121
|
const filterChipLabel =
|
|
@@ -105,10 +128,17 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
105
128
|
`filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
|
|
106
129
|
]
|
|
107
130
|
: '';
|
|
108
|
-
const filterPlaceholder =
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
131
|
+
const filterPlaceholder =
|
|
132
|
+
inputIndex === undefined
|
|
133
|
+
? localization.filterByColumn?.replace(
|
|
134
|
+
'{column}',
|
|
135
|
+
String(column.columnDef.header),
|
|
136
|
+
)
|
|
137
|
+
: inputIndex === 0
|
|
138
|
+
? localization.min
|
|
139
|
+
: inputIndex === 1
|
|
140
|
+
? localization.max
|
|
141
|
+
: '';
|
|
112
142
|
|
|
113
143
|
return (
|
|
114
144
|
<>
|
|
@@ -124,48 +154,53 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
124
154
|
title: filterPlaceholder,
|
|
125
155
|
}}
|
|
126
156
|
helperText={
|
|
127
|
-
|
|
128
|
-
{
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
157
|
+
!inputIndex ? (
|
|
158
|
+
<label htmlFor={filterId}>
|
|
159
|
+
{filterFn instanceof Function
|
|
160
|
+
? localization.filterMode.replace(
|
|
161
|
+
'{filterType}',
|
|
162
|
+
// @ts-ignore
|
|
163
|
+
localization[
|
|
164
|
+
`filter${
|
|
165
|
+
filterFn.name.charAt(0).toUpperCase() +
|
|
166
|
+
filterFn.name.slice(1)
|
|
167
|
+
}`
|
|
168
|
+
] ?? '',
|
|
169
|
+
) ?? ''
|
|
170
|
+
: localization.filterMode.replace(
|
|
171
|
+
'{filterType}',
|
|
172
|
+
// @ts-ignore
|
|
173
|
+
localization[
|
|
174
|
+
`filter${
|
|
175
|
+
filterFn.charAt(0).toUpperCase() + filterFn.slice(1)
|
|
176
|
+
}`
|
|
177
|
+
],
|
|
178
|
+
)}
|
|
179
|
+
</label>
|
|
180
|
+
) : null
|
|
149
181
|
}
|
|
150
182
|
FormHelperTextProps={{
|
|
151
|
-
sx: {
|
|
183
|
+
sx: {
|
|
184
|
+
fontSize: '0.6rem',
|
|
185
|
+
lineHeight: '0.8rem',
|
|
186
|
+
whiteSpace: 'nowrap',
|
|
187
|
+
},
|
|
152
188
|
}}
|
|
153
189
|
label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
|
|
154
190
|
margin="none"
|
|
155
191
|
placeholder={
|
|
156
|
-
filterPlaceholder
|
|
157
|
-
// filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
192
|
+
filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
158
193
|
}
|
|
159
194
|
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
160
195
|
setFilterValue(event.target.value);
|
|
161
|
-
|
|
196
|
+
handleChangeDebounced(event);
|
|
162
197
|
}}
|
|
163
198
|
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
164
199
|
select={isSelectFilter}
|
|
165
200
|
value={filterValue ?? ''}
|
|
166
201
|
variant="standard"
|
|
167
202
|
InputProps={{
|
|
168
|
-
startAdornment: !isSelectFilter && (
|
|
203
|
+
startAdornment: !isSelectFilter && !inputIndex && (
|
|
169
204
|
<InputAdornment position="start">
|
|
170
205
|
<Tooltip arrow title={localization.changeFilterMode}>
|
|
171
206
|
<span>
|
|
@@ -217,7 +252,7 @@ export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
|
217
252
|
sx={{
|
|
218
253
|
m: '-0.25rem',
|
|
219
254
|
p: 0,
|
|
220
|
-
minWidth: !filterChipLabel ? '
|
|
255
|
+
minWidth: !filterChipLabel ? '6rem' : 'auto',
|
|
221
256
|
width: 'calc(100% + 0.5rem)',
|
|
222
257
|
mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
|
|
223
258
|
'& .MuiSelect-icon': {
|
|
@@ -17,9 +17,7 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
17
17
|
getRowModel,
|
|
18
18
|
getSelectedRowModel,
|
|
19
19
|
getState,
|
|
20
|
-
getToggleAllRowsSelectedProps,
|
|
21
20
|
options: {
|
|
22
|
-
isLoading,
|
|
23
21
|
localization,
|
|
24
22
|
muiSelectCheckboxProps,
|
|
25
23
|
onSelectChange,
|
|
@@ -31,14 +29,14 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
31
29
|
|
|
32
30
|
const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
33
31
|
if (selectAll) {
|
|
34
|
-
|
|
32
|
+
tableInstance.getToggleAllRowsSelectedHandler()(event as any);
|
|
35
33
|
onSelectAllChange?.({
|
|
36
34
|
event,
|
|
37
35
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
38
36
|
tableInstance,
|
|
39
37
|
});
|
|
40
38
|
} else if (row) {
|
|
41
|
-
row?.
|
|
39
|
+
row?.getToggleSelectedHandler()(event as any);
|
|
42
40
|
onSelectChange?.({
|
|
43
41
|
event,
|
|
44
42
|
row,
|
|
@@ -52,20 +50,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
52
50
|
}
|
|
53
51
|
};
|
|
54
52
|
|
|
55
|
-
const
|
|
53
|
+
const checkboxProps =
|
|
56
54
|
muiSelectCheckboxProps instanceof Function
|
|
57
55
|
? muiSelectCheckboxProps({ isSelectAll: !!selectAll, row, tableInstance })
|
|
58
56
|
: muiSelectCheckboxProps;
|
|
59
57
|
|
|
60
|
-
const rtSelectCheckboxProps = selectAll
|
|
61
|
-
? getToggleAllRowsSelectedProps()
|
|
62
|
-
: row?.getToggleSelectedProps();
|
|
63
|
-
|
|
64
|
-
const checkboxProps = {
|
|
65
|
-
...rtSelectCheckboxProps,
|
|
66
|
-
...mTableBodyRowSelectCheckboxProps,
|
|
67
|
-
};
|
|
68
|
-
|
|
69
58
|
return (
|
|
70
59
|
<Tooltip
|
|
71
60
|
arrow
|
|
@@ -76,20 +65,29 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
76
65
|
}
|
|
77
66
|
>
|
|
78
67
|
<Checkbox
|
|
79
|
-
|
|
68
|
+
checked={
|
|
69
|
+
selectAll
|
|
70
|
+
? tableInstance.getIsAllRowsSelected()
|
|
71
|
+
: row?.getIsSelected()
|
|
72
|
+
}
|
|
73
|
+
indeterminate={
|
|
74
|
+
selectAll
|
|
75
|
+
? tableInstance.getIsSomeRowsSelected()
|
|
76
|
+
: row?.getIsSomeSelected()
|
|
77
|
+
}
|
|
80
78
|
inputProps={{
|
|
81
79
|
'aria-label': selectAll
|
|
82
80
|
? localization.toggleSelectAll
|
|
83
81
|
: localization.toggleSelectRow,
|
|
84
82
|
}}
|
|
83
|
+
onChange={handleSelectChange}
|
|
85
84
|
size={isDensePadding ? 'small' : 'medium'}
|
|
86
85
|
{...checkboxProps}
|
|
87
86
|
sx={{
|
|
88
87
|
height: isDensePadding ? '1.75rem' : '2.25rem',
|
|
89
88
|
width: isDensePadding ? '1.75rem' : '2.25rem',
|
|
89
|
+
...checkboxProps?.sx,
|
|
90
90
|
}}
|
|
91
|
-
onChange={handleSelectChange}
|
|
92
|
-
title={undefined}
|
|
93
91
|
/>
|
|
94
92
|
</Tooltip>
|
|
95
93
|
);
|