material-react-table 2.0.0-alpha.1 → 2.0.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/README.md +2 -2
- package/dist/cjs/index.js +2400 -2365
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +1 -1
- package/dist/cjs/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/cjs/types/buttons/MRT_RowPinButton.d.ts +2 -2
- package/dist/cjs/types/column.utils.d.ts +6 -6
- package/dist/cjs/types/filterFns.d.ts +14 -14
- package/dist/cjs/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/cjs/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/cjs/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/cjs/types/icons.d.ts +1 -1
- package/dist/cjs/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/cjs/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/cjs/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/cjs/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/cjs/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/cjs/types/types.d.ts +198 -198
- package/dist/esm/material-react-table.esm.js +2027 -1993
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +1 -1
- package/dist/esm/types/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/esm/types/buttons/MRT_RowPinButton.d.ts +2 -2
- package/dist/esm/types/column.utils.d.ts +6 -6
- package/dist/esm/types/filterFns.d.ts +14 -14
- package/dist/esm/types/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/esm/types/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/esm/types/hooks/useMRT_DisplayColumns.d.ts +3 -3
- package/dist/esm/types/icons.d.ts +1 -1
- package/dist/esm/types/inputs/MRT_FilterRangeSlider.d.ts +1 -1
- package/dist/esm/types/menus/MRT_ColumnActionMenu.d.ts +4 -4
- package/dist/esm/types/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/esm/types/toolbar/MRT_TablePagination.d.ts +2 -2
- package/dist/esm/types/toolbar/MRT_TopToolbar.d.ts +1 -1
- package/dist/esm/types/types.d.ts +198 -198
- package/dist/index.d.ts +239 -239
- package/locales/fr.esm.js +1 -1
- package/locales/fr.esm.js.map +1 -1
- package/locales/fr.js +1 -1
- package/locales/fr.js.map +1 -1
- package/locales/tr.d.ts +2 -0
- package/locales/tr.esm.d.ts +2 -0
- package/locales/tr.esm.js +93 -0
- package/locales/tr.esm.js.map +1 -0
- package/locales/tr.js +97 -0
- package/locales/tr.js.map +1 -0
- package/locales/uk.d.ts +2 -0
- package/locales/uk.esm.d.ts +2 -0
- package/locales/uk.esm.js +93 -0
- package/locales/uk.esm.js.map +1 -0
- package/locales/uk.js +97 -0
- package/locales/uk.js.map +1 -0
- package/locales/vi.d.ts +2 -0
- package/locales/vi.esm.d.ts +2 -0
- package/locales/vi.esm.js +93 -0
- package/locales/vi.esm.js.map +1 -0
- package/locales/vi.js +97 -0
- package/locales/vi.js.map +1 -0
- package/locales/zh-Hans.d.ts +2 -0
- package/locales/zh-Hans.esm.d.ts +2 -0
- package/locales/zh-Hans.esm.js +93 -0
- package/locales/zh-Hans.esm.js.map +1 -0
- package/locales/zh-Hans.js +97 -0
- package/locales/zh-Hans.js.map +1 -0
- package/locales/zh-Hant.d.ts +2 -0
- package/locales/zh-Hant.esm.d.ts +2 -0
- package/locales/zh-Hant.esm.js +93 -0
- package/locales/zh-Hant.esm.js.map +1 -0
- package/locales/zh-Hant.js +97 -0
- package/locales/zh-Hant.js.map +1 -0
- package/package.json +2 -1
- package/src/MaterialReactTable.tsx +2 -2
- package/src/body/MRT_TableBody.tsx +9 -9
- package/src/body/MRT_TableBodyCell.tsx +22 -22
- package/src/body/MRT_TableBodyCellValue.tsx +5 -5
- package/src/body/MRT_TableBodyRow.tsx +32 -32
- package/src/body/MRT_TableBodyRowGrabHandle.tsx +2 -2
- package/src/body/MRT_TableBodyRowPinButton.tsx +3 -3
- package/src/body/MRT_TableDetailPanel.tsx +3 -3
- package/src/buttons/MRT_CopyButton.tsx +1 -1
- package/src/buttons/MRT_EditActionButtons.tsx +4 -4
- package/src/buttons/MRT_ExpandAllButton.tsx +3 -3
- package/src/buttons/MRT_ExpandButton.tsx +1 -1
- package/src/buttons/MRT_GrabHandleButton.tsx +10 -10
- package/src/buttons/MRT_RowPinButton.tsx +5 -5
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +1 -1
- package/src/buttons/MRT_ToggleFullScreenButton.tsx +2 -2
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +8 -8
- package/src/column.utils.ts +23 -17
- package/src/filterFns.ts +29 -29
- package/src/footer/MRT_TableFooter.tsx +9 -9
- package/src/footer/MRT_TableFooterCell.tsx +1 -1
- package/src/footer/MRT_TableFooterRow.tsx +2 -2
- package/src/head/MRT_TableHead.tsx +9 -9
- package/src/head/MRT_TableHeadCell.tsx +10 -6
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +9 -6
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +11 -4
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +106 -61
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +2 -2
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +11 -11
- package/src/head/MRT_TableHeadCellSortLabel.tsx +8 -8
- package/src/head/MRT_TableHeadRow.tsx +2 -2
- package/src/hooks/useMRT_DisplayColumns.tsx +5 -5
- package/src/hooks/useMRT_Effects.ts +3 -3
- package/src/hooks/useMRT_TableInstance.ts +15 -14
- package/src/hooks/useMRT_TableOptions.ts +3 -3
- package/src/icons.ts +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +9 -9
- package/src/inputs/MRT_FilterCheckbox.tsx +7 -7
- package/src/inputs/MRT_FilterRangeFields.tsx +1 -1
- package/src/inputs/MRT_FilterRangeSlider.tsx +6 -6
- package/src/inputs/MRT_FilterTextField.tsx +75 -75
- package/src/inputs/MRT_GlobalFilterTextField.tsx +26 -26
- package/src/inputs/MRT_SelectCheckbox.tsx +7 -7
- package/src/locales/fr.ts +1 -1
- package/src/menus/MRT_ColumnActionMenu.tsx +14 -14
- package/src/menus/MRT_FilterOptionMenu.tsx +35 -35
- package/src/menus/MRT_RowActionMenu.tsx +7 -7
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -6
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +5 -5
- package/src/modals/MRT_EditRowModal.tsx +8 -8
- package/src/sortingFns.ts +1 -1
- package/src/table/MRT_Table.tsx +7 -7
- package/src/table/MRT_TableContainer.tsx +10 -10
- package/src/table/MRT_TablePaper.tsx +9 -9
- package/src/toolbar/MRT_BottomToolbar.tsx +5 -5
- package/src/toolbar/MRT_LinearProgressBar.tsx +4 -4
- package/src/toolbar/MRT_TablePagination.tsx +19 -19
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +4 -4
- package/src/toolbar/MRT_ToolbarDropZone.tsx +6 -6
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -5
- package/src/toolbar/MRT_TopToolbar.tsx +7 -7
- package/src/types.ts +263 -263
- package/src/useMaterialReactTable.ts +1 -1
@@ -1,8 +1,10 @@
|
|
1
|
-
import { type MouseEvent } from 'react';
|
1
|
+
import { type MouseEvent, useState } from 'react';
|
2
2
|
import Box from '@mui/material/Box';
|
3
3
|
import Grow from '@mui/material/Grow';
|
4
4
|
import IconButton from '@mui/material/IconButton';
|
5
|
+
import Popover from '@mui/material/Popover';
|
5
6
|
import Tooltip from '@mui/material/Tooltip';
|
7
|
+
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
|
6
8
|
import { type MRT_Header, type MRT_TableInstance } from '../types';
|
7
9
|
|
8
10
|
interface Props<TData extends Record<string, any>> {
|
@@ -11,13 +13,14 @@ interface Props<TData extends Record<string, any>> {
|
|
11
13
|
}
|
12
14
|
|
13
15
|
export const MRT_TableHeadCellFilterLabel = <
|
14
|
-
TData extends Record<string, any
|
16
|
+
TData extends Record<string, any> = {},
|
15
17
|
>({
|
16
18
|
header,
|
17
19
|
table,
|
18
20
|
}: Props<TData>) => {
|
19
21
|
const {
|
20
22
|
options: {
|
23
|
+
columnFilterDisplayMode,
|
21
24
|
icons: { FilterAltIcon },
|
22
25
|
localization,
|
23
26
|
},
|
@@ -27,71 +30,113 @@ export const MRT_TableHeadCellFilterLabel = <
|
|
27
30
|
const { column } = header;
|
28
31
|
const { columnDef } = column;
|
29
32
|
|
33
|
+
const filterValue = column.getFilterValue();
|
34
|
+
|
35
|
+
const [anchorEl, setAnchorEl] = useState<HTMLButtonElement | null>(null);
|
36
|
+
|
37
|
+
const isFilterActive =
|
38
|
+
(Array.isArray(filterValue) && filterValue.some(Boolean)) ||
|
39
|
+
(!!filterValue && !Array.isArray(filterValue));
|
40
|
+
|
30
41
|
const isRangeFilter =
|
31
|
-
|
42
|
+
columnDef.filterVariant === 'range' ||
|
32
43
|
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
33
44
|
columnDef._filterFn,
|
34
45
|
);
|
35
46
|
const currentFilterOption = columnDef._filterFn;
|
36
|
-
const filterTooltip =
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
47
|
+
const filterTooltip =
|
48
|
+
columnFilterDisplayMode === 'popover' && !isFilterActive
|
49
|
+
? localization.filterByColumn?.replace(
|
50
|
+
'{column}',
|
51
|
+
String(columnDef.header),
|
52
|
+
)
|
53
|
+
: localization.filteringByColumn
|
54
|
+
.replace('{column}', String(columnDef.header))
|
55
|
+
.replace(
|
56
|
+
'{filterType}',
|
57
|
+
currentFilterOption
|
58
|
+
? // @ts-ignore
|
59
|
+
localization[
|
60
|
+
`filter${
|
61
|
+
currentFilterOption?.charAt(0)?.toUpperCase() +
|
62
|
+
currentFilterOption?.slice(1)
|
63
|
+
}`
|
64
|
+
]
|
65
|
+
: '',
|
66
|
+
)
|
67
|
+
.replace(
|
68
|
+
'{filterValue}',
|
69
|
+
`"${
|
70
|
+
Array.isArray(column.getFilterValue())
|
71
|
+
? (column.getFilterValue() as [string, string]).join(
|
72
|
+
`" ${isRangeFilter ? localization.and : localization.or} "`,
|
73
|
+
)
|
74
|
+
: (column.getFilterValue() as string)
|
75
|
+
}"`,
|
76
|
+
)
|
77
|
+
.replace('" "', '');
|
59
78
|
|
60
79
|
return (
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
(
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
80
|
+
<>
|
81
|
+
<Grow
|
82
|
+
in={
|
83
|
+
columnFilterDisplayMode === 'popover' ||
|
84
|
+
(!!column.getFilterValue() && !isRangeFilter) ||
|
85
|
+
(isRangeFilter && // @ts-ignore
|
86
|
+
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
|
87
|
+
}
|
88
|
+
unmountOnExit
|
89
|
+
>
|
90
|
+
<Box component="span" sx={{ flex: '0 0' }}>
|
91
|
+
<Tooltip arrow placement="top" title={filterTooltip}>
|
92
|
+
<IconButton
|
93
|
+
disableRipple
|
94
|
+
onClick={(event: MouseEvent<HTMLButtonElement>) => {
|
95
|
+
if (columnFilterDisplayMode === 'popover') {
|
96
|
+
setAnchorEl(event.currentTarget);
|
97
|
+
} else {
|
98
|
+
setShowColumnFilters(true);
|
99
|
+
}
|
100
|
+
queueMicrotask(() => {
|
101
|
+
filterInputRefs.current[`${column.id}-0`]?.focus();
|
102
|
+
filterInputRefs.current[`${column.id}-0`]?.select();
|
103
|
+
});
|
104
|
+
event.stopPropagation();
|
105
|
+
}}
|
106
|
+
sx={{
|
107
|
+
height: '16px',
|
108
|
+
opacity: 0.8,
|
109
|
+
p: '8px',
|
110
|
+
transform: 'scale(0.75)',
|
111
|
+
width: '16px',
|
112
|
+
}}
|
113
|
+
>
|
114
|
+
<FilterAltIcon />
|
115
|
+
</IconButton>
|
116
|
+
</Tooltip>
|
117
|
+
</Box>
|
118
|
+
</Grow>
|
119
|
+
<Popover
|
120
|
+
anchorEl={anchorEl}
|
121
|
+
anchorOrigin={{
|
122
|
+
horizontal: 'center',
|
123
|
+
vertical: 'top',
|
124
|
+
}}
|
125
|
+
onClose={(event) => {
|
126
|
+
//@ts-ignore
|
127
|
+
event.stopPropagation();
|
128
|
+
setAnchorEl(null);
|
129
|
+
}}
|
130
|
+
open={!!anchorEl}
|
131
|
+
transformOrigin={{
|
132
|
+
horizontal: 'center',
|
133
|
+
vertical: 'bottom',
|
134
|
+
}}
|
135
|
+
>
|
136
|
+
<Box sx={{ p: '1rem' }}>
|
137
|
+
<MRT_TableHeadCellFilterContainer header={header} table={table} />
|
138
|
+
</Box>
|
139
|
+
</Popover>
|
140
|
+
</>
|
96
141
|
);
|
97
142
|
};
|
@@ -22,7 +22,7 @@ export const MRT_TableHeadCellGrabHandle = <TData extends Record<string, any>>({
|
|
22
22
|
setHoveredColumn,
|
23
23
|
} = table;
|
24
24
|
const { columnDef } = column;
|
25
|
-
const {
|
25
|
+
const { columnOrder, draggingColumn, hoveredColumn } = getState();
|
26
26
|
|
27
27
|
const iconButtonProps = {
|
28
28
|
...parseFromValuesOrFunc(muiColumnDragHandleProps, { column, table }),
|
@@ -62,8 +62,8 @@ export const MRT_TableHeadCellGrabHandle = <TData extends Record<string, any>>({
|
|
62
62
|
return (
|
63
63
|
<MRT_GrabHandleButton
|
64
64
|
iconButtonProps={iconButtonProps}
|
65
|
-
onDragStart={handleDragStart}
|
66
65
|
onDragEnd={handleDragEnd}
|
66
|
+
onDragStart={handleDragStart}
|
67
67
|
table={table}
|
68
68
|
/>
|
69
69
|
);
|
@@ -33,23 +33,23 @@ export const MRT_TableHeadCellResizeHandle = <
|
|
33
33
|
}}
|
34
34
|
onMouseDown={header.getResizeHandler()}
|
35
35
|
onTouchStart={header.getResizeHandler()}
|
36
|
-
sx={(theme) => ({
|
37
|
-
cursor: 'col-resize',
|
38
|
-
mr: density === 'compact' ? '-0.75rem' : '-1rem',
|
39
|
-
position: 'absolute',
|
40
|
-
right: '4px',
|
41
|
-
px: '4px',
|
42
|
-
'&:active > hr': {
|
43
|
-
backgroundColor: theme.palette.info.main,
|
44
|
-
opacity: 1,
|
45
|
-
},
|
46
|
-
})}
|
47
36
|
style={{
|
48
37
|
transform:
|
49
38
|
column.getIsResizing() && columnResizeMode === 'onEnd'
|
50
39
|
? `translateX(${getState().columnSizingInfo.deltaOffset ?? 0}px)`
|
51
40
|
: undefined,
|
52
41
|
}}
|
42
|
+
sx={(theme) => ({
|
43
|
+
'&:active > hr': {
|
44
|
+
backgroundColor: theme.palette.info.main,
|
45
|
+
opacity: 1,
|
46
|
+
},
|
47
|
+
cursor: 'col-resize',
|
48
|
+
mr: density === 'compact' ? '-0.75rem' : '-1rem',
|
49
|
+
position: 'absolute',
|
50
|
+
px: '4px',
|
51
|
+
right: '4px',
|
52
|
+
})}
|
53
53
|
>
|
54
54
|
<Divider
|
55
55
|
className="Mui-TableHeadCell-ResizeHandle-Divider"
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import Badge from '@mui/material/Badge';
|
2
|
+
import { type TableCellProps } from '@mui/material/TableCell';
|
2
3
|
import TableSortLabel from '@mui/material/TableSortLabel';
|
3
4
|
import Tooltip from '@mui/material/Tooltip';
|
4
5
|
import { type MRT_Header, type MRT_TableInstance } from '../types';
|
5
|
-
import { type TableCellProps } from '@mui/material/TableCell';
|
6
6
|
|
7
7
|
interface Props<TData extends Record<string, any>> {
|
8
8
|
header: MRT_Header<TData>;
|
@@ -41,25 +41,25 @@ export const MRT_TableHeadCellSortLabel = <TData extends Record<string, any>>({
|
|
41
41
|
overlap="circular"
|
42
42
|
>
|
43
43
|
<TableSortLabel
|
44
|
-
|
44
|
+
IconComponent={ArrowDownwardIcon}
|
45
45
|
active={!!column.getIsSorted()}
|
46
|
+
aria-label={sortTooltip}
|
46
47
|
direction={
|
47
48
|
column.getIsSorted()
|
48
49
|
? (column.getIsSorted() as 'asc' | 'desc')
|
49
50
|
: undefined
|
50
51
|
}
|
52
|
+
onClick={(e) => {
|
53
|
+
e.stopPropagation();
|
54
|
+
header.column.getToggleSortingHandler()?.(e);
|
55
|
+
}}
|
51
56
|
sx={{
|
52
57
|
flex: '0 0',
|
53
|
-
width: '2.4ch',
|
54
58
|
transform:
|
55
59
|
tableCellProps?.align !== 'right'
|
56
60
|
? 'translateX(-0.5ch)'
|
57
61
|
: undefined,
|
58
|
-
|
59
|
-
IconComponent={ArrowDownwardIcon}
|
60
|
-
onClick={(e) => {
|
61
|
-
e.stopPropagation();
|
62
|
-
header.column.getToggleSortingHandler()?.(e);
|
62
|
+
width: '2.4ch',
|
63
63
|
}}
|
64
64
|
/>
|
65
65
|
</Badge>
|
@@ -1,13 +1,13 @@
|
|
1
|
+
import { type VirtualItem } from '@tanstack/react-virtual';
|
1
2
|
import TableRow from '@mui/material/TableRow';
|
2
3
|
import { alpha, lighten } from '@mui/material/styles';
|
3
4
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
4
|
-
import {
|
5
|
+
import { parseFromValuesOrFunc } from '../column.utils';
|
5
6
|
import {
|
6
7
|
type MRT_Header,
|
7
8
|
type MRT_HeaderGroup,
|
8
9
|
type MRT_TableInstance,
|
9
10
|
} from '../types';
|
10
|
-
import { parseFromValuesOrFunc } from '../column.utils';
|
11
11
|
|
12
12
|
interface Props<TData extends Record<string, any>> {
|
13
13
|
headerGroup: MRT_HeaderGroup<TData>;
|
@@ -1,29 +1,29 @@
|
|
1
1
|
import { type RefObject, useMemo } from 'react';
|
2
|
-
import { showExpandColumn } from '../column.utils';
|
3
|
-
import { MRT_TableBodyRowPinButton } from '../body/MRT_TableBodyRowPinButton';
|
4
2
|
import { MRT_TableBodyRowGrabHandle } from '../body';
|
3
|
+
import { MRT_TableBodyRowPinButton } from '../body/MRT_TableBodyRowPinButton';
|
5
4
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
6
5
|
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
7
6
|
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
7
|
+
import { showExpandColumn } from '../column.utils';
|
8
8
|
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
9
9
|
import {
|
10
10
|
type MRT_ColumnDef,
|
11
11
|
type MRT_ColumnOrderState,
|
12
|
-
type MRT_GroupingState,
|
13
12
|
type MRT_DefinedTableOptions,
|
13
|
+
type MRT_GroupingState,
|
14
14
|
type MRT_Row,
|
15
15
|
} from '../types';
|
16
16
|
|
17
17
|
interface Params<TData extends Record<string, any>> {
|
18
|
-
creatingRow: MRT_Row<TData> | null;
|
19
18
|
columnOrder: MRT_ColumnOrderState;
|
19
|
+
creatingRow: MRT_Row<TData> | null;
|
20
20
|
grouping: MRT_GroupingState;
|
21
21
|
tableOptions: MRT_DefinedTableOptions<TData>;
|
22
22
|
}
|
23
23
|
|
24
24
|
export const useMRT_DisplayColumns = <TData extends Record<string, any>>({
|
25
|
-
creatingRow,
|
26
25
|
columnOrder,
|
26
|
+
creatingRow,
|
27
27
|
grouping,
|
28
28
|
tableOptions,
|
29
29
|
}: Params<TData>) => {
|
@@ -12,10 +12,10 @@ export const useMRT_Effects = <TData extends Record<string, any> = {}>(
|
|
12
12
|
const {
|
13
13
|
globalFilter,
|
14
14
|
isFullScreen,
|
15
|
-
pagination,
|
16
|
-
sorting,
|
17
15
|
isLoading,
|
16
|
+
pagination,
|
18
17
|
showSkeletons,
|
18
|
+
sorting,
|
19
19
|
} = getState();
|
20
20
|
|
21
21
|
const isMounted = useRef(false);
|
@@ -38,8 +38,8 @@ export const useMRT_Effects = <TData extends Record<string, any> = {}>(
|
|
38
38
|
if (!previousTop.current) return;
|
39
39
|
//restore scroll position
|
40
40
|
window.scrollTo({
|
41
|
-
top: -1 * (previousTop.current as number),
|
42
41
|
behavior: 'instant',
|
42
|
+
top: -1 * (previousTop.current as number),
|
43
43
|
});
|
44
44
|
}
|
45
45
|
}
|
@@ -19,16 +19,14 @@ import {
|
|
19
19
|
getDefaultColumnOrderIds,
|
20
20
|
prepareColumns,
|
21
21
|
} from '../column.utils';
|
22
|
-
import { useMRT_DisplayColumns } from './useMRT_DisplayColumns';
|
23
|
-
import { useMRT_Effects } from './useMRT_Effects';
|
24
22
|
import {
|
25
23
|
type MRT_Cell,
|
26
24
|
type MRT_Column,
|
27
25
|
type MRT_ColumnDef,
|
26
|
+
type MRT_ColumnFilterFnsState,
|
28
27
|
type MRT_ColumnOrderState,
|
29
28
|
type MRT_DefinedTableOptions,
|
30
29
|
type MRT_DensityState,
|
31
|
-
type MRT_ColumnFilterFnsState,
|
32
30
|
type MRT_FilterOption,
|
33
31
|
type MRT_GroupingState,
|
34
32
|
type MRT_Row,
|
@@ -36,6 +34,8 @@ import {
|
|
36
34
|
type MRT_TableState,
|
37
35
|
type MRT_Updater,
|
38
36
|
} from '../types';
|
37
|
+
import { useMRT_DisplayColumns } from './useMRT_DisplayColumns';
|
38
|
+
import { useMRT_Effects } from './useMRT_Effects';
|
39
39
|
|
40
40
|
export const useMRT_TableInstance: <TData extends Record<string, any>>(
|
41
41
|
tableOptions: MRT_DefinedTableOptions<TData>,
|
@@ -104,10 +104,10 @@ export const useMRT_TableInstance: <TData extends Record<string, any>>(
|
|
104
104
|
initialState.grouping ?? [],
|
105
105
|
);
|
106
106
|
const [hoveredColumn, setHoveredColumn] = useState<
|
107
|
-
|
107
|
+
{ id: string } | MRT_Column<TData> | null
|
108
108
|
>(initialState.hoveredColumn ?? null);
|
109
109
|
const [hoveredRow, setHoveredRow] = useState<
|
110
|
-
|
110
|
+
{ id: string } | MRT_Row<TData> | null
|
111
111
|
>(initialState.hoveredRow ?? null);
|
112
112
|
const [isFullScreen, setIsFullScreen] = useState<boolean>(
|
113
113
|
initialState?.isFullScreen ?? false,
|
@@ -207,9 +207,9 @@ export const useMRT_TableInstance: <TData extends Record<string, any>>(
|
|
207
207
|
getSortedRowModel: tableOptions.enableSorting
|
208
208
|
? getSortedRowModel()
|
209
209
|
: undefined,
|
210
|
+
getSubRows: (row) => row?.subRows,
|
210
211
|
onColumnOrderChange: setColumnOrder,
|
211
212
|
onGroupingChange: setGrouping,
|
212
|
-
getSubRows: (row) => row?.subRows,
|
213
213
|
...tableOptions,
|
214
214
|
//@ts-ignore
|
215
215
|
columns: columnDefs,
|
@@ -217,9 +217,9 @@ export const useMRT_TableInstance: <TData extends Record<string, any>>(
|
|
217
217
|
globalFilterFn: tableOptions.filterFns?.[globalFilterFn ?? 'fuzzy'],
|
218
218
|
initialState,
|
219
219
|
state: {
|
220
|
-
creatingRow,
|
221
220
|
columnFilterFns,
|
222
221
|
columnOrder,
|
222
|
+
creatingRow,
|
223
223
|
density,
|
224
224
|
draggingColumn,
|
225
225
|
draggingRow,
|
@@ -248,23 +248,24 @@ export const useMRT_TableInstance: <TData extends Record<string, any>>(
|
|
248
248
|
searchInputRef,
|
249
249
|
// @ts-ignore
|
250
250
|
tableContainerRef,
|
251
|
+
// @ts-ignore
|
252
|
+
tableFooterRef,
|
251
253
|
tableHeadCellRefs,
|
252
254
|
// @ts-ignore
|
255
|
+
tableHeadRef,
|
256
|
+
// @ts-ignore
|
253
257
|
tablePaperRef,
|
254
258
|
// @ts-ignore
|
255
259
|
topToolbarRef,
|
256
|
-
// @ts-ignore
|
257
|
-
tableFooterRef,
|
258
|
-
// @ts-ignore
|
259
|
-
tableHeadRef,
|
260
260
|
};
|
261
261
|
|
262
262
|
const setCreatingRow = (row: MRT_Updater<MRT_Row<TData> | null | true>) => {
|
263
|
+
let _row = row;
|
263
264
|
if (row === true) {
|
264
|
-
|
265
|
-
} else {
|
266
|
-
_setCreatingRow(row as MRT_Row<TData> | null);
|
265
|
+
_row = createRow(table);
|
267
266
|
}
|
267
|
+
tableOptions?.onCreatingRowChange?.(_row as MRT_Row<TData> | null) ??
|
268
|
+
_setCreatingRow(_row as MRT_Row<TData> | null);
|
268
269
|
};
|
269
270
|
|
270
271
|
table.setCreatingRow = setCreatingRow;
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import { useMemo } from 'react';
|
2
2
|
import { MRT_AggregationFns } from '../aggregationFns';
|
3
|
-
import { MRT_FilterFns } from '../filterFns';
|
4
|
-
import { MRT_SortingFns } from '../sortingFns';
|
5
3
|
import { MRT_DefaultColumn, MRT_DefaultDisplayColumn } from '../column.utils';
|
6
|
-
import {
|
4
|
+
import { MRT_FilterFns } from '../filterFns';
|
7
5
|
import { MRT_Default_Icons } from '../icons';
|
6
|
+
import { MRT_Localization_EN } from '../locales/en';
|
7
|
+
import { MRT_SortingFns } from '../sortingFns';
|
8
8
|
import { type MRT_DefinedTableOptions, type MRT_TableOptions } from '../types';
|
9
9
|
|
10
10
|
export const useMRT_TableOptions: <TData extends Record<string, any>>(
|
package/src/icons.ts
CHANGED
@@ -13,8 +13,8 @@ import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
13
13
|
import FilterAltIcon from '@mui/icons-material/FilterAlt';
|
14
14
|
import FilterListIcon from '@mui/icons-material/FilterList';
|
15
15
|
import FilterListOffIcon from '@mui/icons-material/FilterListOff';
|
16
|
-
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
17
16
|
import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
17
|
+
import FullscreenExitIcon from '@mui/icons-material/FullscreenExit';
|
18
18
|
import KeyboardDoubleArrowDownIcon from '@mui/icons-material/KeyboardDoubleArrowDown';
|
19
19
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
20
20
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
@@ -36,7 +36,6 @@ export interface MRT_Icons {
|
|
36
36
|
DensityLargeIcon: any;
|
37
37
|
DensityMediumIcon: any;
|
38
38
|
DensitySmallIcon: any;
|
39
|
-
KeyboardDoubleArrowDownIcon: any;
|
40
39
|
DragHandleIcon: any;
|
41
40
|
DynamicFeedIcon: any;
|
42
41
|
EditIcon: any;
|
@@ -46,6 +45,7 @@ export interface MRT_Icons {
|
|
46
45
|
FilterListOffIcon: any;
|
47
46
|
FullscreenExitIcon: any;
|
48
47
|
FullscreenIcon: any;
|
48
|
+
KeyboardDoubleArrowDownIcon: any;
|
49
49
|
MoreHorizIcon: any;
|
50
50
|
MoreVertIcon: any;
|
51
51
|
PushPinIcon: any;
|
@@ -4,8 +4,8 @@ import {
|
|
4
4
|
type KeyboardEvent,
|
5
5
|
useState,
|
6
6
|
} from 'react';
|
7
|
-
import TextField from '@mui/material/TextField';
|
8
7
|
import MenuItem from '@mui/material/MenuItem';
|
8
|
+
import TextField from '@mui/material/TextField';
|
9
9
|
import { type TextFieldProps } from '@mui/material/TextField';
|
10
10
|
import { parseFromValuesOrFunc } from '../column.utils';
|
11
11
|
import { type MRT_Cell, type MRT_TableInstance } from '../types';
|
@@ -23,9 +23,9 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
|
|
23
23
|
getState,
|
24
24
|
options: { createDisplayMode, editDisplayMode, muiEditTextFieldProps },
|
25
25
|
refs: { editInputRefs },
|
26
|
+
setCreatingRow,
|
26
27
|
setEditingCell,
|
27
28
|
setEditingRow,
|
28
|
-
setCreatingRow,
|
29
29
|
} = table;
|
30
30
|
const { column, row } = cell;
|
31
31
|
const { columnDef } = column;
|
@@ -100,7 +100,7 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
|
|
100
100
|
}
|
101
101
|
}}
|
102
102
|
label={
|
103
|
-
['
|
103
|
+
['custom', 'modal'].includes(
|
104
104
|
(isCreating ? createDisplayMode : editDisplayMode) as string,
|
105
105
|
)
|
106
106
|
? column.columnDef.header
|
@@ -109,7 +109,7 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
|
|
109
109
|
margin="none"
|
110
110
|
name={column.id}
|
111
111
|
placeholder={
|
112
|
-
!['
|
112
|
+
!['custom', 'modal'].includes(
|
113
113
|
(isCreating ? createDisplayMode : editDisplayMode) as string,
|
114
114
|
)
|
115
115
|
? columnDef.header
|
@@ -119,17 +119,17 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
|
|
119
119
|
value={value}
|
120
120
|
variant="standard"
|
121
121
|
{...textFieldProps}
|
122
|
+
onBlur={handleBlur}
|
123
|
+
onChange={handleChange}
|
122
124
|
onClick={(e) => {
|
123
125
|
e.stopPropagation();
|
124
126
|
textFieldProps?.onClick?.(e);
|
125
127
|
}}
|
126
|
-
onBlur={handleBlur}
|
127
|
-
onChange={handleChange}
|
128
128
|
onKeyDown={handleEnterKeyDown}
|
129
129
|
>
|
130
130
|
{textFieldProps.children ??
|
131
131
|
columnDef?.editSelectOptions?.map(
|
132
|
-
(option:
|
132
|
+
(option: { text: string; value: string } | string) => {
|
133
133
|
let value: string;
|
134
134
|
let text: string;
|
135
135
|
if (typeof option !== 'object') {
|
@@ -143,10 +143,10 @@ export const MRT_EditCellTextField = <TData extends Record<string, any>>({
|
|
143
143
|
<MenuItem
|
144
144
|
key={value}
|
145
145
|
sx={{
|
146
|
-
display: 'flex',
|
147
|
-
m: 0,
|
148
146
|
alignItems: 'center',
|
147
|
+
display: 'flex',
|
149
148
|
gap: '0.5rem',
|
149
|
+
m: 0,
|
150
150
|
}}
|
151
151
|
value={value}
|
152
152
|
>
|
@@ -1,8 +1,8 @@
|
|
1
1
|
import Checkbox from '@mui/material/Checkbox';
|
2
2
|
import FormControlLabel from '@mui/material/FormControlLabel';
|
3
3
|
import Tooltip from '@mui/material/Tooltip';
|
4
|
-
import { type MRT_Column, type MRT_TableInstance } from '../types';
|
5
4
|
import { parseFromValuesOrFunc } from '../column.utils';
|
5
|
+
import { type MRT_Column, type MRT_TableInstance } from '../types';
|
6
6
|
|
7
7
|
interface Props<TData extends Record<string, any>> {
|
8
8
|
column: MRT_Column<TData>;
|
@@ -47,16 +47,12 @@ export const MRT_FilterCheckbox = <TData extends Record<string, any>>({
|
|
47
47
|
control={
|
48
48
|
<Checkbox
|
49
49
|
checked={column.getFilterValue() === 'true'}
|
50
|
-
indeterminate={column.getFilterValue() === undefined}
|
51
50
|
color={
|
52
51
|
column.getFilterValue() === undefined ? 'default' : 'primary'
|
53
52
|
}
|
53
|
+
indeterminate={column.getFilterValue() === undefined}
|
54
54
|
size={density === 'compact' ? 'small' : 'medium'}
|
55
55
|
{...checkboxProps}
|
56
|
-
onClick={(e) => {
|
57
|
-
e.stopPropagation();
|
58
|
-
checkboxProps?.onClick?.(e);
|
59
|
-
}}
|
60
56
|
onChange={(e, checked) => {
|
61
57
|
column.setFilterValue(
|
62
58
|
column.getFilterValue() === undefined
|
@@ -67,6 +63,10 @@ export const MRT_FilterCheckbox = <TData extends Record<string, any>>({
|
|
67
63
|
);
|
68
64
|
checkboxProps?.onChange?.(e, checked);
|
69
65
|
}}
|
66
|
+
onClick={(e) => {
|
67
|
+
e.stopPropagation();
|
68
|
+
checkboxProps?.onClick?.(e);
|
69
|
+
}}
|
70
70
|
sx={(theme) => ({
|
71
71
|
height: '2.5rem',
|
72
72
|
width: '2.5rem',
|
@@ -76,7 +76,7 @@ export const MRT_FilterCheckbox = <TData extends Record<string, any>>({
|
|
76
76
|
}
|
77
77
|
disableTypography
|
78
78
|
label={checkboxProps.title ?? filterLabel}
|
79
|
-
sx={{ color: 'text.secondary',
|
79
|
+
sx={{ color: 'text.secondary', fontWeight: 'normal', mt: '-4px' }}
|
80
80
|
title={undefined}
|
81
81
|
/>
|
82
82
|
</Tooltip>
|
@@ -12,7 +12,7 @@ export const MRT_FilterRangeFields = <TData extends Record<string, any>>({
|
|
12
12
|
table,
|
13
13
|
}: Props<TData>) => {
|
14
14
|
return (
|
15
|
-
<Box sx={{ display: 'grid',
|
15
|
+
<Box sx={{ display: 'grid', gap: '1rem', gridTemplateColumns: '1fr 1fr' }}>
|
16
16
|
<MRT_FilterTextField header={header} rangeFilterIndex={0} table={table} />
|
17
17
|
<MRT_FilterTextField header={header} rangeFilterIndex={1} table={table} />
|
18
18
|
</Box>
|