material-react-table 1.1.1 → 1.2.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.
- package/dist/cjs/MaterialReactTable.d.ts +1 -0
- package/dist/cjs/index.js +57 -40
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/MaterialReactTable.d.ts +1 -0
- package/dist/esm/material-react-table.esm.js +57 -40
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +1 -0
- package/src/buttons/MRT_GrabHandleButton.tsx +1 -1
- package/src/head/MRT_TableHeadCell.tsx +75 -44
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +3 -3
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +1 -4
- package/src/head/MRT_TableHeadCellSortLabel.tsx +1 -0
- package/src/inputs/MRT_FilterTextField.tsx +2 -1
- package/src/inputs/MRT_GlobalFilterTextField.tsx +7 -3
- package/src/table/MRT_TableRoot.tsx +2 -0
package/dist/index.d.ts
CHANGED
|
@@ -242,6 +242,7 @@ declare type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<Ta
|
|
|
242
242
|
filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
243
243
|
searchInputRef: MutableRefObject<HTMLInputElement>;
|
|
244
244
|
tableContainerRef: MutableRefObject<HTMLDivElement>;
|
|
245
|
+
tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
|
|
245
246
|
tablePaperRef: MutableRefObject<HTMLDivElement>;
|
|
246
247
|
topToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
247
248
|
};
|
package/package.json
CHANGED
|
@@ -199,6 +199,7 @@ export type MRT_TableInstance<TData extends Record<string, any> = {}> = Omit<
|
|
|
199
199
|
filterInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
|
200
200
|
searchInputRef: MutableRefObject<HTMLInputElement>;
|
|
201
201
|
tableContainerRef: MutableRefObject<HTMLDivElement>;
|
|
202
|
+
tableHeadCellRefs: MutableRefObject<Record<string, HTMLTableCellElement>>;
|
|
202
203
|
tablePaperRef: MutableRefObject<HTMLDivElement>;
|
|
203
204
|
topToolbarRef: MutableRefObject<HTMLDivElement>;
|
|
204
205
|
};
|
|
@@ -26,6 +26,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
26
26
|
enableMultiSort,
|
|
27
27
|
muiTableHeadCellProps,
|
|
28
28
|
},
|
|
29
|
+
refs: { tableHeadCellRefs },
|
|
29
30
|
setHoveredColumn,
|
|
30
31
|
} = table;
|
|
31
32
|
const {
|
|
@@ -54,6 +55,27 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
54
55
|
...mcTableHeadCellProps,
|
|
55
56
|
};
|
|
56
57
|
|
|
58
|
+
const showColumnActions =
|
|
59
|
+
(enableColumnActions || columnDef.enableColumnActions) &&
|
|
60
|
+
columnDef.enableColumnActions !== false;
|
|
61
|
+
|
|
62
|
+
const showDragHandle =
|
|
63
|
+
enableColumnDragging !== false &&
|
|
64
|
+
columnDef.enableColumnDragging !== false &&
|
|
65
|
+
(enableColumnDragging ||
|
|
66
|
+
(enableColumnOrdering && columnDef.enableColumnOrdering !== false) ||
|
|
67
|
+
(enableGrouping &&
|
|
68
|
+
columnDef.enableGrouping !== false &&
|
|
69
|
+
!grouping.includes(column.id)));
|
|
70
|
+
|
|
71
|
+
const headerPL = useMemo(() => {
|
|
72
|
+
let pl = 0;
|
|
73
|
+
if (column.getCanSort()) pl++;
|
|
74
|
+
if (showColumnActions) pl += 1.75;
|
|
75
|
+
if (showDragHandle) pl += 1.25;
|
|
76
|
+
return pl;
|
|
77
|
+
}, [showColumnActions, showDragHandle]);
|
|
78
|
+
|
|
57
79
|
const draggingBorder = useMemo(
|
|
58
80
|
() =>
|
|
59
81
|
draggingColumn?.id === column.id
|
|
@@ -83,22 +105,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
83
105
|
}
|
|
84
106
|
};
|
|
85
107
|
|
|
86
|
-
const headerElement =
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const tableHeadCellRef = React.useRef<HTMLTableCellElement>(null);
|
|
108
|
+
const headerElement =
|
|
109
|
+
columnDef?.Header instanceof Function
|
|
110
|
+
? columnDef?.Header?.({
|
|
111
|
+
column,
|
|
112
|
+
header,
|
|
113
|
+
table,
|
|
114
|
+
})
|
|
115
|
+
: columnDef?.Header ?? (columnDef.header as ReactNode);
|
|
95
116
|
|
|
96
117
|
return (
|
|
97
118
|
<TableCell
|
|
98
119
|
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
99
120
|
colSpan={header.colSpan}
|
|
100
121
|
onDragEnter={handleDragEnter}
|
|
101
|
-
ref={
|
|
122
|
+
ref={(node) => {
|
|
123
|
+
if (node) {
|
|
124
|
+
tableHeadCellRefs.current[column.id] = node as HTMLTableCellElement;
|
|
125
|
+
}
|
|
126
|
+
}}
|
|
102
127
|
{...tableCellProps}
|
|
103
128
|
sx={(theme: Theme) => ({
|
|
104
129
|
fontWeight: 'bold',
|
|
@@ -145,23 +170,24 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
145
170
|
>
|
|
146
171
|
{header.isPlaceholder ? null : (
|
|
147
172
|
<Box
|
|
173
|
+
className="Mui-TableHeadCell-Content"
|
|
148
174
|
sx={{
|
|
149
175
|
alignItems: 'flex-start',
|
|
150
176
|
display: 'flex',
|
|
151
177
|
flexDirection:
|
|
152
178
|
tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
|
|
153
179
|
justifyContent:
|
|
154
|
-
tableCellProps?.align === '
|
|
155
|
-
? 'flex-start'
|
|
156
|
-
: columnDefType === 'group' ||
|
|
157
|
-
tableCellProps?.align === 'center'
|
|
180
|
+
columnDefType === 'group' || tableCellProps?.align === 'center'
|
|
158
181
|
? 'center'
|
|
159
|
-
:
|
|
182
|
+
: column.getCanResize()
|
|
183
|
+
? 'space-between'
|
|
184
|
+
: 'flex-start',
|
|
160
185
|
position: 'relative',
|
|
161
186
|
width: '100%',
|
|
162
187
|
}}
|
|
163
188
|
>
|
|
164
189
|
<Box
|
|
190
|
+
className="Mui-TableHeadCell-Content-Labels"
|
|
165
191
|
onClick={column.getToggleSortingHandler()}
|
|
166
192
|
sx={{
|
|
167
193
|
alignItems: 'center',
|
|
@@ -172,17 +198,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
172
198
|
display: 'flex',
|
|
173
199
|
flexDirection:
|
|
174
200
|
tableCellProps?.align === 'right' ? 'row-reverse' : 'row',
|
|
175
|
-
|
|
176
|
-
m: tableCellProps?.align === 'center' ? 'auto' : undefined,
|
|
201
|
+
overflow: 'hidden',
|
|
177
202
|
pl:
|
|
178
|
-
tableCellProps?.align === 'center'
|
|
179
|
-
?
|
|
203
|
+
tableCellProps?.align === 'center'
|
|
204
|
+
? `${headerPL}rem`
|
|
180
205
|
: undefined,
|
|
181
|
-
whiteSpace:
|
|
182
|
-
(columnDef.header?.length ?? 0) < 24 ? 'nowrap' : 'normal',
|
|
183
206
|
}}
|
|
184
207
|
>
|
|
185
|
-
|
|
208
|
+
<Box
|
|
209
|
+
className="Mui-TableHeadCell-Content-Wrapper"
|
|
210
|
+
sx={{
|
|
211
|
+
overflow: 'hidden',
|
|
212
|
+
textOverflow: 'ellipsis',
|
|
213
|
+
whiteSpace:
|
|
214
|
+
(columnDef.header?.length ?? 0) < 20 ? 'nowrap' : 'normal',
|
|
215
|
+
}}
|
|
216
|
+
title={columnDef.header}
|
|
217
|
+
>
|
|
218
|
+
{headerElement}
|
|
219
|
+
</Box>
|
|
186
220
|
{column.getCanSort() && (
|
|
187
221
|
<MRT_TableHeadCellSortLabel
|
|
188
222
|
header={header}
|
|
@@ -195,28 +229,25 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
|
195
229
|
)}
|
|
196
230
|
</Box>
|
|
197
231
|
{columnDefType !== 'group' && (
|
|
198
|
-
<Box
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
table={table}
|
|
218
|
-
/>
|
|
219
|
-
)}
|
|
232
|
+
<Box
|
|
233
|
+
className="Mui-TableHeadCell-Content-Actions"
|
|
234
|
+
sx={{ whiteSpace: 'nowrap' }}
|
|
235
|
+
>
|
|
236
|
+
{showDragHandle && (
|
|
237
|
+
<MRT_TableHeadCellGrabHandle
|
|
238
|
+
column={column}
|
|
239
|
+
table={table}
|
|
240
|
+
tableHeadCellRef={{
|
|
241
|
+
current: tableHeadCellRefs.current[column.id],
|
|
242
|
+
}}
|
|
243
|
+
/>
|
|
244
|
+
)}
|
|
245
|
+
{showColumnActions && (
|
|
246
|
+
<MRT_TableHeadCellColumnActionsButton
|
|
247
|
+
header={header}
|
|
248
|
+
table={table}
|
|
249
|
+
/>
|
|
250
|
+
)}
|
|
220
251
|
</Box>
|
|
221
252
|
)}
|
|
222
253
|
{column.getCanResize() && (
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC, MouseEvent } from 'react';
|
|
2
|
-
import { Grow, IconButton, Tooltip } from '@mui/material';
|
|
2
|
+
import { Box, Grow, IconButton, Tooltip } from '@mui/material';
|
|
3
3
|
import { MRT_Header, MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
@@ -56,7 +56,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
56
56
|
(!!column.getFilterValue()?.[0] || !!column.getFilterValue()?.[1]))
|
|
57
57
|
}
|
|
58
58
|
>
|
|
59
|
-
<span>
|
|
59
|
+
<Box component="span" sx={{ flex: '0 0' }}>
|
|
60
60
|
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
61
61
|
<IconButton
|
|
62
62
|
disableRipple
|
|
@@ -75,7 +75,7 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({ header, table }) => {
|
|
|
75
75
|
<FilterAltIcon />
|
|
76
76
|
</IconButton>
|
|
77
77
|
</Tooltip>
|
|
78
|
-
</
|
|
78
|
+
</Box>
|
|
79
79
|
</Grow>
|
|
80
80
|
);
|
|
81
81
|
};
|
|
@@ -49,10 +49,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
49
49
|
borderRadius: '2px',
|
|
50
50
|
borderWidth: '2px',
|
|
51
51
|
height:
|
|
52
|
-
showColumnFilters && columnDefType === 'data'
|
|
53
|
-
? '3.5rem'
|
|
54
|
-
: '1.75rem',
|
|
55
|
-
opacity: 0.8,
|
|
52
|
+
showColumnFilters && columnDefType === 'data' ? '3.5rem' : '1.5rem',
|
|
56
53
|
touchAction: 'none',
|
|
57
54
|
transition: column.getIsResizing()
|
|
58
55
|
? undefined
|
|
@@ -38,6 +38,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
38
38
|
columnFilterModeOptions,
|
|
39
39
|
icons: { FilterListIcon, CloseIcon },
|
|
40
40
|
localization,
|
|
41
|
+
manualFiltering,
|
|
41
42
|
muiTableHeadCellFilterTextFieldProps,
|
|
42
43
|
},
|
|
43
44
|
refs: { filterInputRefs },
|
|
@@ -132,7 +133,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
132
133
|
column.setFilterValue(value ?? undefined);
|
|
133
134
|
}
|
|
134
135
|
},
|
|
135
|
-
isTextboxFilter ? 200 : 1,
|
|
136
|
+
isTextboxFilter ? (manualFiltering ? 400 : 200) : 1,
|
|
136
137
|
),
|
|
137
138
|
[],
|
|
138
139
|
);
|
|
@@ -32,6 +32,7 @@ export const MRT_GlobalFilterTextField = <
|
|
|
32
32
|
enableGlobalFilterModes,
|
|
33
33
|
icons: { SearchIcon, CloseIcon },
|
|
34
34
|
localization,
|
|
35
|
+
manualFiltering,
|
|
35
36
|
muiSearchTextFieldProps,
|
|
36
37
|
},
|
|
37
38
|
refs: { searchInputRef },
|
|
@@ -47,9 +48,12 @@ export const MRT_GlobalFilterTextField = <
|
|
|
47
48
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
48
49
|
|
|
49
50
|
const handleChangeDebounced = useCallback(
|
|
50
|
-
debounce(
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
debounce(
|
|
52
|
+
(event: ChangeEvent<HTMLInputElement>) => {
|
|
53
|
+
setGlobalFilter(event.target.value ?? undefined);
|
|
54
|
+
},
|
|
55
|
+
manualFiltering ? 500 : 250,
|
|
56
|
+
),
|
|
53
57
|
[],
|
|
54
58
|
);
|
|
55
59
|
|
|
@@ -46,6 +46,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
46
46
|
const filterInputRefs = useRef<Record<string, HTMLInputElement>>({});
|
|
47
47
|
const searchInputRef = useRef<HTMLInputElement>(null);
|
|
48
48
|
const tableContainerRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
const tableHeadCellRefs = useRef<Record<string, HTMLTableCellElement>>({});
|
|
49
50
|
const tablePaperRef = useRef<HTMLDivElement>(null);
|
|
50
51
|
const topToolbarRef = useRef<HTMLDivElement>(null);
|
|
51
52
|
|
|
@@ -294,6 +295,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
294
295
|
filterInputRefs,
|
|
295
296
|
searchInputRef,
|
|
296
297
|
tableContainerRef,
|
|
298
|
+
tableHeadCellRefs,
|
|
297
299
|
tablePaperRef,
|
|
298
300
|
topToolbarRef,
|
|
299
301
|
},
|