material-react-table 0.7.6 → 0.8.0

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.
Files changed (58) hide show
  1. package/README.md +1 -1
  2. package/dist/MaterialReactTable.d.ts +18 -16
  3. package/dist/body/MRT_TableBody.d.ts +0 -1
  4. package/dist/body/MRT_TableBodyCell.d.ts +1 -0
  5. package/dist/body/MRT_TableBodyRow.d.ts +0 -1
  6. package/dist/buttons/MRT_CopyButton.d.ts +2 -1
  7. package/dist/enums.d.ts +2 -2
  8. package/dist/filtersFNs.d.ts +31 -30
  9. package/dist/footer/MRT_TableFooter.d.ts +0 -1
  10. package/dist/head/MRT_TableHead.d.ts +0 -1
  11. package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
  12. package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
  13. package/dist/localization.d.ts +6 -2
  14. package/dist/material-react-table.cjs.development.js +550 -575
  15. package/dist/material-react-table.cjs.development.js.map +1 -1
  16. package/dist/material-react-table.cjs.production.min.js +1 -1
  17. package/dist/material-react-table.cjs.production.min.js.map +1 -1
  18. package/dist/material-react-table.esm.js +553 -578
  19. package/dist/material-react-table.esm.js.map +1 -1
  20. package/dist/table/MRT_Table.d.ts +0 -1
  21. package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -0
  22. package/dist/toolbar/MRT_ToolbarTop.d.ts +3 -0
  23. package/dist/utils.d.ts +1 -1
  24. package/package.json +24 -27
  25. package/src/MaterialReactTable.tsx +24 -24
  26. package/src/body/MRT_TableBody.tsx +3 -11
  27. package/src/body/MRT_TableBodyCell.tsx +105 -51
  28. package/src/body/MRT_TableBodyRow.tsx +21 -30
  29. package/src/buttons/MRT_ColumnPinningButtons.tsx +28 -40
  30. package/src/buttons/MRT_CopyButton.tsx +5 -3
  31. package/src/buttons/MRT_EditActionButtons.tsx +1 -2
  32. package/src/buttons/MRT_ExpandAllButton.tsx +25 -18
  33. package/src/buttons/MRT_ExpandButton.tsx +27 -21
  34. package/src/enums.ts +2 -2
  35. package/src/filtersFNs.ts +71 -81
  36. package/src/footer/MRT_TableFooter.tsx +6 -16
  37. package/src/footer/MRT_TableFooterCell.tsx +16 -15
  38. package/src/footer/MRT_TableFooterRow.tsx +6 -8
  39. package/src/head/MRT_TableHead.tsx +5 -16
  40. package/src/head/MRT_TableHeadCell.tsx +120 -50
  41. package/src/head/MRT_TableHeadRow.tsx +8 -15
  42. package/src/inputs/MRT_EditCellTextField.tsx +3 -3
  43. package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
  44. package/src/inputs/MRT_FilterTextField.tsx +76 -41
  45. package/src/inputs/MRT_SelectCheckbox.tsx +15 -17
  46. package/src/localization.ts +13 -5
  47. package/src/menus/MRT_ColumnActionMenu.tsx +13 -12
  48. package/src/menus/MRT_FilterOptionMenu.tsx +36 -33
  49. package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
  50. package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +4 -6
  51. package/src/table/MRT_Table.tsx +5 -16
  52. package/src/table/MRT_TableContainer.tsx +7 -78
  53. package/src/table/MRT_TableRoot.tsx +43 -51
  54. package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
  55. package/src/toolbar/MRT_ToolbarAlertBanner.tsx +13 -28
  56. package/src/toolbar/MRT_ToolbarBottom.tsx +23 -5
  57. package/src/toolbar/MRT_ToolbarInternalButtons.tsx +30 -29
  58. package/src/toolbar/MRT_ToolbarTop.tsx +24 -25
@@ -1,19 +1,15 @@
1
1
  import React, { FC } from 'react';
2
2
  import { TableHead } from '@mui/material';
3
3
  import { MRT_TableHeadRow } from './MRT_TableHeadRow';
4
- import type { MRT_HeaderGroup, MRT_TableInstance } from '..';
4
+ import type { MRT_TableInstance } from '..';
5
5
 
6
6
  interface Props {
7
- pinned: 'left' | 'center' | 'right' | 'none';
8
7
  tableInstance: MRT_TableInstance;
9
8
  }
10
9
 
11
- export const MRT_TableHead: FC<Props> = ({ pinned, tableInstance }) => {
10
+ export const MRT_TableHead: FC<Props> = ({ tableInstance }) => {
12
11
  const {
13
- getCenterHeaderGroups,
14
12
  getHeaderGroups,
15
- getLeftHeaderGroups,
16
- getRightHeaderGroups,
17
13
  options: { muiTableHeadProps },
18
14
  } = tableInstance;
19
15
 
@@ -22,19 +18,12 @@ export const MRT_TableHead: FC<Props> = ({ pinned, tableInstance }) => {
22
18
  ? muiTableHeadProps({ tableInstance })
23
19
  : muiTableHeadProps;
24
20
 
25
- const getHeaderGroupsMap = {
26
- center: getCenterHeaderGroups,
27
- left: getLeftHeaderGroups,
28
- none: getHeaderGroups,
29
- right: getRightHeaderGroups,
30
- };
31
-
32
21
  return (
33
22
  <TableHead {...tableHeadProps}>
34
- {getHeaderGroupsMap[pinned]().map((headerGroup) => (
23
+ {getHeaderGroups().map((headerGroup) => (
35
24
  <MRT_TableHeadRow
36
- headerGroup={headerGroup as MRT_HeaderGroup}
37
- key={headerGroup.getHeaderGroupProps().key}
25
+ headerGroup={headerGroup as any}
26
+ key={headerGroup.id}
38
27
  tableInstance={tableInstance}
39
28
  />
40
29
  ))}
@@ -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
- Divider,
6
- Collapse,
9
+ Theme,
7
10
  Tooltip,
8
- Box,
9
- IconButton,
10
11
  alpha,
11
- Theme,
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 { ColumnResizerProps } from '@tanstack/react-table';
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('{column}', column.header)
60
- : localization.sortedByColumnAsc.replace('{column}', column.header)
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.getColumnFilterValue()
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,68 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
74
81
  `filter${filterFn.charAt(0).toUpperCase() + filterFn.slice(1)}`
75
82
  ],
76
83
  )
77
- .replace('{filterValue}', column.getColumnFilterValue() as string)
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
- column?.Header?.({
83
- header,
84
- tableInstance,
85
- }) ?? column.header;
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: theme.palette.background.default,
94
- backgroundImage: `linear-gradient(${alpha(
95
- theme.palette.common.white,
96
- 0.05,
97
- )},${alpha(theme.palette.common.white, 0.05)})`,
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
- maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
101
- minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
140
+ left:
141
+ column.getIsPinned() === 'left'
142
+ ? `${column.getStart('left')}px`
143
+ : undefined,
144
+
145
+ overflow: 'visible',
102
146
  p: isDensePadding
103
147
  ? column.columnDefType === 'display'
104
148
  ? '0 0.5rem'
@@ -106,21 +150,33 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
106
150
  : column.columnDefType === 'display'
107
151
  ? '0.5rem 0.75rem'
108
152
  : '1rem',
153
+ pb: column.columnDefType === 'display' ? 0 : undefined,
154
+ position:
155
+ column.getIsPinned() && column.columnDefType !== 'group'
156
+ ? 'sticky'
157
+ : undefined,
109
158
  pt:
110
159
  column.columnDefType === 'display'
111
160
  ? 0
112
161
  : isDensePadding
113
162
  ? '0.75rem'
114
163
  : '1.25rem',
115
- pb: column.columnDefType === 'display' ? 0 : undefined,
116
- overflow: 'visible',
164
+ right:
165
+ column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
117
166
  transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
118
167
  verticalAlign: 'text-top',
119
- width: header.getWidth(),
120
- zIndex: column.getIsResizing() ? 2 : 1,
121
- //@ts-ignore
122
- ...tableCellProps?.sx,
168
+ zIndex: column.getIsResizing()
169
+ ? 3
170
+ : column.getIsPinned() && column.columnDefType !== 'group'
171
+ ? 2
172
+ : 1,
173
+ ...(tableCellProps?.sx as any),
123
174
  })}
175
+ style={{
176
+ maxWidth: `min(${column.getSize()}px, fit-content)`,
177
+ minWidth: `max(${column.getSize()}px, ${column.minSize ?? 30}px)`,
178
+ width: header.getSize(),
179
+ }}
124
180
  >
125
181
  {header.isPlaceholder ? null : column.columnDefType === 'display' ? (
126
182
  headerElement
@@ -144,7 +200,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
144
200
  : undefined,
145
201
  display: 'flex',
146
202
  flexWrap: 'nowrap',
147
- whiteSpace: column.header.length < 24 ? 'nowrap' : 'normal',
203
+ whiteSpace:
204
+ (column.columnDef.header?.length ?? 0) < 24
205
+ ? 'nowrap'
206
+ : 'normal',
148
207
  }}
149
208
  >
150
209
  {headerElement}
@@ -163,7 +222,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
163
222
  )}
164
223
  {column.columnDefType === 'data' &&
165
224
  enableColumnFilters &&
166
- !!column.getCanColumnFilter() && (
225
+ !!column.getCanFilter() && (
167
226
  <Tooltip arrow placement="top" title={filterTooltip}>
168
227
  <IconButton
169
228
  disableRipple
@@ -174,7 +233,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
174
233
  size="small"
175
234
  sx={{
176
235
  m: 0,
177
- opacity: !!column.getColumnFilterValue() ? 0.8 : 0,
236
+ opacity: !!column.getFilterValue() ? 0.8 : 0,
178
237
  p: '2px',
179
238
  transition: 'all 0.2s ease-in-out',
180
239
  '&:hover': {
@@ -183,7 +242,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
183
242
  },
184
243
  }}
185
244
  >
186
- {showFilters && !column.getColumnFilterValue() ? (
245
+ {showFilters && !column.getFilterValue() ? (
187
246
  <FilterAltOff />
188
247
  ) : (
189
248
  <FilterAltIcon />
@@ -204,7 +263,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
204
263
  <Divider
205
264
  flexItem
206
265
  orientation="vertical"
207
- onDoubleClick={() => header.resetSize()}
266
+ onDoubleClick={() => column.resetSize()}
208
267
  sx={(theme: Theme) => ({
209
268
  borderRadius: '2px',
210
269
  borderRightWidth: '2px',
@@ -217,7 +276,9 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
217
276
  position: 'absolute',
218
277
  right: '1px',
219
278
  touchAction: 'none',
220
- transition: 'all 0.2s ease-in-out',
279
+ transition: column.getIsResizing()
280
+ ? undefined
281
+ : 'all 0.2s ease-in-out',
221
282
  userSelect: 'none',
222
283
  zIndex: 2000,
223
284
  '&:active': {
@@ -225,21 +286,30 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
225
286
  opacity: 1,
226
287
  },
227
288
  })}
228
- {...(header.getResizerProps((props: ColumnResizerProps) => ({
229
- ...props,
230
- style: {
231
- transform: column.getIsResizing()
232
- ? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
233
- : '',
234
- },
235
- })) as any)}
289
+ onMouseDown={header.getResizeHandler()}
290
+ onTouchStart={header.getResizeHandler()}
291
+ style={{
292
+ transform: column.getIsResizing()
293
+ ? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
294
+ : 'none',
295
+ }}
236
296
  />
237
297
  )}
238
298
  </Box>
239
299
  )}
240
- {column.columnDefType === 'data' && column.getCanColumnFilter() && (
241
- <Collapse in={showFilters}>
242
- <MRT_FilterTextField header={header} tableInstance={tableInstance} />
300
+ {column.columnDefType === 'data' && column.getCanFilter() && (
301
+ <Collapse in={showFilters} mountOnEnter unmountOnExit>
302
+ {currentFilterFns[column.id] === MRT_FILTER_OPTION.BETWEEN ? (
303
+ <MRT_FilterRangeFields
304
+ header={header}
305
+ tableInstance={tableInstance}
306
+ />
307
+ ) : (
308
+ <MRT_FilterTextField
309
+ header={header}
310
+ tableInstance={tableInstance}
311
+ />
312
+ )}
243
313
  </Collapse>
244
314
  )}
245
315
  </TableCell>
@@ -1,5 +1,5 @@
1
- import React, { CSSProperties, FC } from '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 mTableHeadRowProps =
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
- boxShadow: `4px 0 8px ${alpha(theme.palette.common.black, 0.1)}`,
32
- //@ts-ignore
33
- ...tableRowProps?.sx,
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.value);
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.values[column.id] = value;
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> = ({ header, tableInstance }) => {
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
- (column.getColumnFilterValue() ?? '') as string,
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 handleChange = useCallback(
71
+ const handleChangeDebounced = useCallback(
65
72
  debounce(
66
73
  (event: ChangeEvent<HTMLInputElement>) =>
67
- column.setColumnFilterValue(event.target.value ?? undefined),
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
- column.setColumnFilterValue(undefined);
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.setColumnFilterValue(undefined);
105
+ column.setFilterValue(undefined);
85
106
  setCurrentFilterFns((prev) => ({
86
107
  ...prev,
87
- [header.id]: MRT_FILTER_OPTION.BEST_MATCH,
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 = localization.filterByColumn?.replace(
109
- '{column}',
110
- String(column.header),
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
- <label htmlFor={filterId}>
128
- {filterFn instanceof Function
129
- ? localization.filterMode.replace(
130
- '{filterType}',
131
- // @ts-ignore
132
- localization[
133
- `filter${
134
- filterFn.name.charAt(0).toUpperCase() +
135
- filterFn.name.slice(1)
136
- }`
137
- ] ?? '',
138
- ) ?? ''
139
- : localization.filterMode.replace(
140
- '{filterType}',
141
- // @ts-ignore
142
- localization[
143
- `filter${
144
- filterFn.charAt(0).toUpperCase() + filterFn.slice(1)
145
- }`
146
- ],
147
- )}
148
- </label>
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: { fontSize: '0.6rem', lineHeight: '0.8rem' },
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
- handleChange(event);
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 ? '5rem' : 'auto',
255
+ minWidth: !filterChipLabel ? '6rem' : 'auto',
221
256
  width: 'calc(100% + 0.5rem)',
222
257
  mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
223
258
  '& .MuiSelect-icon': {