material-react-table 0.6.9 → 0.7.0-alpha.10
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 +29 -19
- package/dist/MaterialReactTable.d.ts +314 -108
- 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 +2 -1
- 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/enums.d.ts +2 -1
- package/dist/filtersFNs.d.ts +13 -5
- 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 +10 -2
- package/dist/material-react-table.cjs.development.js +2286 -2459
- 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 +2288 -2461
- 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 +29 -30
- package/src/MaterialReactTable.tsx +614 -297
- package/src/body/MRT_TableBody.tsx +26 -22
- package/src/body/MRT_TableBodyCell.tsx +79 -55
- package/src/body/MRT_TableBodyRow.tsx +37 -67
- package/src/body/MRT_TableDetailPanel.tsx +21 -17
- package/src/buttons/MRT_CopyButton.tsx +34 -10
- package/src/buttons/MRT_EditActionButtons.tsx +16 -13
- package/src/buttons/MRT_ExpandAllButton.tsx +36 -28
- package/src/buttons/MRT_ExpandButton.tsx +35 -41
- 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 +31 -26
- package/src/buttons/MRT_ToggleSearchButton.tsx +24 -12
- package/src/enums.ts +2 -1
- package/src/filtersFNs.ts +17 -3
- 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 +185 -142
- package/src/head/MRT_TableHeadRow.tsx +16 -93
- package/src/icons.ts +3 -3
- package/src/inputs/MRT_EditCellTextField.tsx +39 -24
- package/src/inputs/MRT_FilterTextField.tsx +53 -39
- package/src/inputs/MRT_SearchTextField.tsx +71 -25
- package/src/inputs/MRT_SelectCheckbox.tsx +42 -30
- package/src/localization.ts +20 -4
- package/src/menus/MRT_ColumnActionMenu.tsx +129 -69
- package/src/menus/MRT_FilterTypeMenu.tsx +55 -23
- package/src/menus/MRT_RowActionMenu.tsx +22 -15
- 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 +239 -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 -27
- 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 -215
|
@@ -1,114 +1,37 @@
|
|
|
1
|
-
import React, { FC
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
MRT_TableHeadCell,
|
|
6
|
-
} from './MRT_TableHeadCell';
|
|
7
|
-
import { commonTableBodyButtonCellStyles } from '../body/MRT_TableBodyCell';
|
|
8
|
-
import { useMRT } from '../useMRT';
|
|
9
|
-
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
10
|
-
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
11
|
-
import { MRT_TableSpacerCell } from '../table/MRT_TableSpacerCell';
|
|
12
|
-
import { MRT_TableHeadCellActions } from './MRT_TableHeadCellActions';
|
|
13
|
-
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 '..';
|
|
14
5
|
|
|
15
6
|
interface Props {
|
|
16
7
|
headerGroup: MRT_HeaderGroup;
|
|
8
|
+
tableInstance: MRT_TableInstance;
|
|
17
9
|
}
|
|
18
10
|
|
|
19
|
-
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup }) => {
|
|
11
|
+
export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
20
12
|
const {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
disableSelectAll,
|
|
24
|
-
enableRowActions,
|
|
25
|
-
enableRowEditing,
|
|
26
|
-
enableRowNumbers,
|
|
27
|
-
enableSelection,
|
|
28
|
-
muiTableHeadRowProps,
|
|
29
|
-
positionActionsColumn,
|
|
30
|
-
renderDetailPanel,
|
|
31
|
-
tableInstance,
|
|
32
|
-
} = useMRT();
|
|
33
|
-
|
|
34
|
-
const isParentHeader = useMemo(
|
|
35
|
-
() => headerGroup.headers.some((h) => (h.columns?.length ?? 0) > 0),
|
|
36
|
-
[headerGroup.headers],
|
|
37
|
-
);
|
|
13
|
+
options: { muiTableHeadRowProps },
|
|
14
|
+
} = tableInstance;
|
|
38
15
|
|
|
39
16
|
const mTableHeadRowProps =
|
|
40
17
|
muiTableHeadRowProps instanceof Function
|
|
41
|
-
? muiTableHeadRowProps(headerGroup)
|
|
18
|
+
? muiTableHeadRowProps({ headerGroup, tableInstance })
|
|
42
19
|
: muiTableHeadRowProps;
|
|
43
20
|
|
|
44
21
|
const tableRowProps = {
|
|
22
|
+
...headerGroup?.getHeaderGroupProps(),
|
|
45
23
|
...mTableHeadRowProps,
|
|
46
|
-
...headerGroup.getHeaderGroupProps(),
|
|
47
|
-
style: {
|
|
48
|
-
...headerGroup.getHeaderGroupProps().style,
|
|
49
|
-
...mTableHeadRowProps?.style,
|
|
50
|
-
},
|
|
51
24
|
};
|
|
52
25
|
|
|
53
26
|
return (
|
|
54
27
|
<TableRow {...tableRowProps}>
|
|
55
|
-
{
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
...commonTableHeadCellStyles(tableInstance.state.densePadding),
|
|
62
|
-
}}
|
|
63
|
-
>
|
|
64
|
-
#
|
|
65
|
-
</TableCell>
|
|
66
|
-
))}
|
|
67
|
-
{(enableRowActions || enableRowEditing) &&
|
|
68
|
-
positionActionsColumn === 'first' &&
|
|
69
|
-
(isParentHeader ? (
|
|
70
|
-
<MRT_TableSpacerCell />
|
|
71
|
-
) : (
|
|
72
|
-
<MRT_TableHeadCellActions />
|
|
73
|
-
))}
|
|
74
|
-
{anyRowsCanExpand || renderDetailPanel ? (
|
|
75
|
-
!disableExpandAll && !isParentHeader ? (
|
|
76
|
-
<MRT_ExpandAllButton />
|
|
77
|
-
) : (
|
|
78
|
-
<MRT_TableSpacerCell
|
|
79
|
-
width={`${
|
|
80
|
-
renderDetailPanel ? 2 : tableInstance.expandedDepth + 0.5
|
|
81
|
-
}rem`}
|
|
82
|
-
/>
|
|
83
|
-
)
|
|
84
|
-
) : null}
|
|
85
|
-
{enableSelection ? (
|
|
86
|
-
!isParentHeader && !disableSelectAll ? (
|
|
87
|
-
<TableCell
|
|
88
|
-
sx={{
|
|
89
|
-
...commonTableBodyButtonCellStyles(
|
|
90
|
-
tableInstance.state.densePadding,
|
|
91
|
-
),
|
|
92
|
-
maxWidth: '3rem',
|
|
93
|
-
width: '3rem',
|
|
94
|
-
}}
|
|
95
|
-
>
|
|
96
|
-
<MRT_SelectCheckbox selectAll />
|
|
97
|
-
</TableCell>
|
|
98
|
-
) : (
|
|
99
|
-
<MRT_TableSpacerCell width="1rem" />
|
|
100
|
-
)
|
|
101
|
-
) : null}
|
|
102
|
-
{headerGroup.headers.map((column: MRT_HeaderGroup) => (
|
|
103
|
-
<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
|
+
/>
|
|
104
34
|
))}
|
|
105
|
-
{(enableRowActions || enableRowEditing) &&
|
|
106
|
-
positionActionsColumn === 'last' &&
|
|
107
|
-
(isParentHeader ? (
|
|
108
|
-
<MRT_TableSpacerCell />
|
|
109
|
-
) : (
|
|
110
|
-
<MRT_TableHeadCellActions />
|
|
111
|
-
))}
|
|
112
35
|
</TableRow>
|
|
113
36
|
);
|
|
114
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,57 +1,72 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
FC,
|
|
4
|
+
FocusEvent,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import { TextField } from '@mui/material';
|
|
3
|
-
import {
|
|
4
|
-
import type { MRT_Cell } from '..';
|
|
9
|
+
import type { MRT_Cell, MRT_Row, MRT_TableInstance } from '..';
|
|
5
10
|
|
|
6
11
|
interface Props {
|
|
7
12
|
cell: MRT_Cell;
|
|
13
|
+
tableInstance: MRT_TableInstance;
|
|
8
14
|
}
|
|
9
15
|
|
|
10
|
-
export const MRT_EditCellTextField: FC<Props> = ({ cell }) => {
|
|
16
|
+
export const MRT_EditCellTextField: FC<Props> = ({ cell, tableInstance }) => {
|
|
11
17
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
getState,
|
|
19
|
+
options: {
|
|
20
|
+
enableEditing,
|
|
21
|
+
muiTableBodyCellEditTextFieldProps,
|
|
22
|
+
setCurrentEditingRow,
|
|
16
23
|
},
|
|
17
|
-
} =
|
|
24
|
+
} = tableInstance;
|
|
25
|
+
|
|
26
|
+
const [value, setValue] = useState(cell.value);
|
|
27
|
+
|
|
28
|
+
const { column, row } = cell;
|
|
18
29
|
|
|
19
30
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
setValue(event.target.value);
|
|
32
|
+
column.onCellEditChange?.({ event, cell, tableInstance });
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const handleBlur = (event: FocusEvent<HTMLInputElement>) => {
|
|
36
|
+
if (getState().currentEditingRow) {
|
|
37
|
+
row.values[column.id] = value;
|
|
38
|
+
setCurrentEditingRow({ ...getState().currentEditingRow } as MRT_Row);
|
|
25
39
|
}
|
|
26
|
-
|
|
40
|
+
column.onCellEditBlur?.({ event, cell, tableInstance });
|
|
27
41
|
};
|
|
28
42
|
|
|
29
43
|
const mTableBodyCellEditTextFieldProps =
|
|
30
44
|
muiTableBodyCellEditTextFieldProps instanceof Function
|
|
31
|
-
? muiTableBodyCellEditTextFieldProps(cell)
|
|
45
|
+
? muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
32
46
|
: muiTableBodyCellEditTextFieldProps;
|
|
33
47
|
|
|
34
48
|
const mcTableBodyCellEditTextFieldProps =
|
|
35
|
-
|
|
36
|
-
?
|
|
37
|
-
:
|
|
49
|
+
column.muiTableBodyCellEditTextFieldProps instanceof Function
|
|
50
|
+
? column.muiTableBodyCellEditTextFieldProps({ cell, tableInstance })
|
|
51
|
+
: column.muiTableBodyCellEditTextFieldProps;
|
|
38
52
|
|
|
39
53
|
const textFieldProps = {
|
|
40
54
|
...mTableBodyCellEditTextFieldProps,
|
|
41
55
|
...mcTableBodyCellEditTextFieldProps,
|
|
42
56
|
};
|
|
43
57
|
|
|
44
|
-
if (
|
|
45
|
-
return <>{
|
|
58
|
+
if (enableEditing && column.enableEditing !== false && column.Edit) {
|
|
59
|
+
return <>{column.Edit?.({ cell, tableInstance })}</>;
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
return (
|
|
49
63
|
<TextField
|
|
50
64
|
margin="dense"
|
|
65
|
+
onBlur={handleBlur}
|
|
51
66
|
onChange={handleChange}
|
|
52
|
-
onClick={(e) => e.stopPropagation()}
|
|
53
|
-
placeholder={
|
|
54
|
-
value={
|
|
67
|
+
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
68
|
+
placeholder={column.header}
|
|
69
|
+
value={value}
|
|
55
70
|
variant="standard"
|
|
56
71
|
{...textFieldProps}
|
|
57
72
|
/>
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
FC,
|
|
4
|
+
MouseEvent,
|
|
5
|
+
useCallback,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
2
8
|
import {
|
|
3
9
|
Chip,
|
|
10
|
+
debounce,
|
|
4
11
|
IconButton,
|
|
5
12
|
InputAdornment,
|
|
6
13
|
MenuItem,
|
|
@@ -8,36 +15,41 @@ import {
|
|
|
8
15
|
TextFieldProps,
|
|
9
16
|
Tooltip,
|
|
10
17
|
} from '@mui/material';
|
|
11
|
-
import {
|
|
12
|
-
import { useMRT } from '../useMRT';
|
|
13
|
-
import type { MRT_HeaderGroup } from '..';
|
|
18
|
+
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
14
19
|
import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
|
|
15
20
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
16
21
|
|
|
17
22
|
interface Props {
|
|
18
|
-
|
|
23
|
+
header: MRT_Header;
|
|
24
|
+
tableInstance: MRT_TableInstance;
|
|
19
25
|
}
|
|
20
26
|
|
|
21
|
-
export const MRT_FilterTextField: FC<Props> = ({
|
|
27
|
+
export const MRT_FilterTextField: FC<Props> = ({ header, tableInstance }) => {
|
|
22
28
|
const {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
getState,
|
|
30
|
+
options: {
|
|
31
|
+
icons: { FilterListIcon, CloseIcon },
|
|
32
|
+
idPrefix,
|
|
33
|
+
localization,
|
|
34
|
+
muiTableHeadCellFilterTextFieldProps,
|
|
35
|
+
setCurrentFilterTypes,
|
|
36
|
+
},
|
|
37
|
+
} = tableInstance;
|
|
38
|
+
|
|
39
|
+
const { column } = header;
|
|
40
|
+
|
|
41
|
+
const { currentFilterTypes } = getState();
|
|
30
42
|
|
|
31
43
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
32
44
|
|
|
33
45
|
const mTableHeadCellFilterTextFieldProps =
|
|
34
46
|
muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
35
|
-
? muiTableHeadCellFilterTextFieldProps(column)
|
|
47
|
+
? muiTableHeadCellFilterTextFieldProps({ column, tableInstance })
|
|
36
48
|
: muiTableHeadCellFilterTextFieldProps;
|
|
37
49
|
|
|
38
50
|
const mcTableHeadCellFilterTextFieldProps =
|
|
39
51
|
column.muiTableHeadCellFilterTextFieldProps instanceof Function
|
|
40
|
-
? column.muiTableHeadCellFilterTextFieldProps(column)
|
|
52
|
+
? column.muiTableHeadCellFilterTextFieldProps({ column, tableInstance })
|
|
41
53
|
: column.muiTableHeadCellFilterTextFieldProps;
|
|
42
54
|
|
|
43
55
|
const textFieldProps = {
|
|
@@ -45,11 +57,18 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
45
57
|
...mcTableHeadCellFilterTextFieldProps,
|
|
46
58
|
} as TextFieldProps;
|
|
47
59
|
|
|
48
|
-
const [filterValue, setFilterValue] = useState(
|
|
60
|
+
const [filterValue, setFilterValue] = useState<string>(
|
|
61
|
+
(column.getColumnFilterValue() ?? '') as string,
|
|
62
|
+
);
|
|
49
63
|
|
|
50
|
-
const handleChange =
|
|
51
|
-
|
|
52
|
-
|
|
64
|
+
const handleChange = useCallback(
|
|
65
|
+
debounce(
|
|
66
|
+
(event: ChangeEvent<HTMLInputElement>) =>
|
|
67
|
+
column.setColumnFilterValue(event.target.value ?? undefined),
|
|
68
|
+
150,
|
|
69
|
+
),
|
|
70
|
+
[],
|
|
71
|
+
);
|
|
53
72
|
|
|
54
73
|
const handleFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
55
74
|
setAnchorEl(event.currentTarget);
|
|
@@ -57,24 +76,24 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
57
76
|
|
|
58
77
|
const handleClear = () => {
|
|
59
78
|
setFilterValue('');
|
|
60
|
-
column.
|
|
79
|
+
column.setColumnFilterValue(undefined);
|
|
61
80
|
};
|
|
62
81
|
|
|
63
82
|
const handleClearFilterChip = () => {
|
|
64
83
|
setFilterValue('');
|
|
65
|
-
column.
|
|
84
|
+
column.setColumnFilterValue(undefined);
|
|
66
85
|
setCurrentFilterTypes((prev) => ({
|
|
67
86
|
...prev,
|
|
68
|
-
[
|
|
87
|
+
[header.id]: MRT_FILTER_TYPE.BEST_MATCH,
|
|
69
88
|
}));
|
|
70
89
|
};
|
|
71
90
|
|
|
72
91
|
if (column.Filter) {
|
|
73
|
-
return <>{column.Filter?.({
|
|
92
|
+
return <>{column.Filter?.({ header, tableInstance })}</>;
|
|
74
93
|
}
|
|
75
94
|
|
|
76
|
-
const filterId = `mrt-${idPrefix}-${
|
|
77
|
-
const filterType =
|
|
95
|
+
const filterId = `mrt-${idPrefix}-${header.id}-filter-text-field`;
|
|
96
|
+
const filterType = currentFilterTypes?.[header.id];
|
|
78
97
|
const isSelectFilter = !!column.filterSelectOptions;
|
|
79
98
|
const filterChipLabel =
|
|
80
99
|
!(filterType instanceof Function) &&
|
|
@@ -88,7 +107,7 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
88
107
|
: '';
|
|
89
108
|
const filterPlaceholder = localization.filterByColumn?.replace(
|
|
90
109
|
'{column}',
|
|
91
|
-
String(column.
|
|
110
|
+
String(column.header),
|
|
92
111
|
);
|
|
93
112
|
|
|
94
113
|
return (
|
|
@@ -132,22 +151,16 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
132
151
|
sx: { fontSize: '0.6rem', lineHeight: '0.8rem' },
|
|
133
152
|
}}
|
|
134
153
|
label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
|
|
135
|
-
InputLabelProps={{
|
|
136
|
-
shrink: false,
|
|
137
|
-
sx: {
|
|
138
|
-
maxWidth: 'calc(100% - 2.5rem)',
|
|
139
|
-
},
|
|
140
|
-
title: filterPlaceholder,
|
|
141
|
-
}}
|
|
142
154
|
margin="none"
|
|
143
155
|
placeholder={
|
|
144
|
-
|
|
156
|
+
filterPlaceholder
|
|
157
|
+
// filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
145
158
|
}
|
|
146
|
-
onChange={(
|
|
147
|
-
setFilterValue(
|
|
148
|
-
handleChange(
|
|
159
|
+
onChange={(event: ChangeEvent<HTMLInputElement>) => {
|
|
160
|
+
setFilterValue(event.target.value);
|
|
161
|
+
handleChange(event);
|
|
149
162
|
}}
|
|
150
|
-
onClick={(e) => e.stopPropagation()}
|
|
163
|
+
onClick={(e: MouseEvent<HTMLInputElement>) => e.stopPropagation()}
|
|
151
164
|
select={isSelectFilter}
|
|
152
165
|
value={filterValue ?? ''}
|
|
153
166
|
variant="standard"
|
|
@@ -237,8 +250,9 @@ export const MRT_FilterTextField: FC<Props> = ({ column }) => {
|
|
|
237
250
|
</TextField>
|
|
238
251
|
<MRT_FilterTypeMenu
|
|
239
252
|
anchorEl={anchorEl}
|
|
240
|
-
|
|
253
|
+
header={header}
|
|
241
254
|
setAnchorEl={setAnchorEl}
|
|
255
|
+
tableInstance={tableInstance}
|
|
242
256
|
/>
|
|
243
257
|
</>
|
|
244
258
|
);
|
|
@@ -1,37 +1,67 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
ChangeEvent,
|
|
3
|
+
FC,
|
|
4
|
+
MouseEvent,
|
|
5
|
+
useCallback,
|
|
6
|
+
useState,
|
|
7
|
+
} from 'react';
|
|
8
|
+
import {
|
|
9
|
+
Collapse,
|
|
10
|
+
debounce,
|
|
11
|
+
IconButton,
|
|
12
|
+
InputAdornment,
|
|
13
|
+
TextField,
|
|
14
|
+
Tooltip,
|
|
15
|
+
} from '@mui/material';
|
|
16
|
+
import { MRT_FilterTypeMenu } from '../menus/MRT_FilterTypeMenu';
|
|
17
|
+
import { MRT_TableInstance } from '..';
|
|
5
18
|
|
|
6
|
-
interface Props {
|
|
19
|
+
interface Props {
|
|
20
|
+
tableInstance: MRT_TableInstance;
|
|
21
|
+
}
|
|
7
22
|
|
|
8
|
-
export const MRT_SearchTextField: FC<Props> = () => {
|
|
23
|
+
export const MRT_SearchTextField: FC<Props> = ({ tableInstance }) => {
|
|
9
24
|
const {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
25
|
+
getState,
|
|
26
|
+
setGlobalFilter,
|
|
27
|
+
options: {
|
|
28
|
+
icons: { SearchIcon, CloseIcon },
|
|
29
|
+
idPrefix,
|
|
30
|
+
localization,
|
|
31
|
+
muiSearchTextFieldProps,
|
|
32
|
+
onGlobalFilterChange,
|
|
33
|
+
},
|
|
34
|
+
} = tableInstance;
|
|
17
35
|
|
|
18
|
-
const
|
|
36
|
+
const { globalFilter, showSearch } = getState();
|
|
19
37
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
39
|
+
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
40
|
+
|
|
41
|
+
const handleChange = useCallback(
|
|
42
|
+
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
|
43
|
+
setGlobalFilter(event.target.value ?? undefined);
|
|
44
|
+
onGlobalFilterChange?.({ event, tableInstance });
|
|
45
|
+
}, 200),
|
|
46
|
+
[],
|
|
26
47
|
);
|
|
27
48
|
|
|
49
|
+
const handleGlobalFilterMenuOpen = (event: MouseEvent<HTMLElement>) => {
|
|
50
|
+
setAnchorEl(event.currentTarget);
|
|
51
|
+
};
|
|
52
|
+
|
|
28
53
|
const handleClear = () => {
|
|
29
54
|
setSearchValue('');
|
|
30
|
-
|
|
55
|
+
setGlobalFilter(undefined);
|
|
31
56
|
};
|
|
32
57
|
|
|
58
|
+
const textFieldProps =
|
|
59
|
+
muiSearchTextFieldProps instanceof Function
|
|
60
|
+
? muiSearchTextFieldProps({ tableInstance })
|
|
61
|
+
: muiSearchTextFieldProps;
|
|
62
|
+
|
|
33
63
|
return (
|
|
34
|
-
<Collapse in={
|
|
64
|
+
<Collapse in={showSearch} orientation="horizontal">
|
|
35
65
|
<TextField
|
|
36
66
|
id={`mrt-${idPrefix}-search-text-field`}
|
|
37
67
|
placeholder={localization.search}
|
|
@@ -44,7 +74,18 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
44
74
|
InputProps={{
|
|
45
75
|
startAdornment: (
|
|
46
76
|
<InputAdornment position="start">
|
|
47
|
-
<
|
|
77
|
+
<Tooltip arrow title={localization.changeSearchMode}>
|
|
78
|
+
<span>
|
|
79
|
+
<IconButton
|
|
80
|
+
aria-label={localization.changeSearchMode}
|
|
81
|
+
onClick={handleGlobalFilterMenuOpen}
|
|
82
|
+
size="small"
|
|
83
|
+
sx={{ height: '1.75rem', width: '1.75rem' }}
|
|
84
|
+
>
|
|
85
|
+
<SearchIcon fontSize="small" />
|
|
86
|
+
</IconButton>
|
|
87
|
+
</span>
|
|
88
|
+
</Tooltip>
|
|
48
89
|
</InputAdornment>
|
|
49
90
|
),
|
|
50
91
|
endAdornment: (
|
|
@@ -61,8 +102,13 @@ export const MRT_SearchTextField: FC<Props> = () => {
|
|
|
61
102
|
</InputAdornment>
|
|
62
103
|
),
|
|
63
104
|
}}
|
|
64
|
-
{...
|
|
65
|
-
sx={{ justifySelf: 'end', ...
|
|
105
|
+
{...textFieldProps}
|
|
106
|
+
sx={{ justifySelf: 'end', ...textFieldProps?.sx }}
|
|
107
|
+
/>
|
|
108
|
+
<MRT_FilterTypeMenu
|
|
109
|
+
anchorEl={anchorEl}
|
|
110
|
+
setAnchorEl={setAnchorEl}
|
|
111
|
+
tableInstance={tableInstance}
|
|
66
112
|
/>
|
|
67
113
|
</Collapse>
|
|
68
114
|
);
|