material-react-table 0.7.1 → 0.7.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 +1 -1
- package/dist/icons.d.ts +1 -0
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +66 -29
- 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 +66 -29
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +4 -0
- package/src/body/MRT_TableBodyCell.tsx +3 -0
- package/src/footer/MRT_TableFooterCell.tsx +3 -0
- package/src/head/MRT_TableHeadCell.tsx +52 -53
- package/src/head/MRT_TableHeadRow.tsx +12 -3
- package/src/icons.ts +3 -0
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +26 -4
- package/src/table/MRT_TableContainer.tsx +3 -4
- package/src/table/MRT_TableRoot.tsx +1 -4
- package/src/utils.ts +5 -1
package/dist/utils.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
|
|
|
7
7
|
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterTypes: {
|
|
8
8
|
[key: string]: MRT_FilterType;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "defaultCanHide" | "defaultIsVisible" | "enablePinning" | "defaultCanPin" | "filterFn" | "enableAllFilters" | "enableColumnFilter" | "enableGlobalFilter" | "defaultCanFilter" | "defaultCanColumnFilter" | "defaultCanGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "defaultCanSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregateValue" | "aggregatedCell" | "enableGrouping" | "defaultCanGroup" | "enableResizing" | "defaultCanResize" | "width" | "minWidth" | "maxWidth" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterTypes" | "filter" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.7.
|
|
2
|
+
"version": "0.7.2",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/react-table": "^8.0.0-alpha.
|
|
100
|
+
"@tanstack/react-table": "^8.0.0-alpha.45",
|
|
101
101
|
"match-sorter": "^6.3.1"
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -723,8 +723,10 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
723
723
|
|
|
724
724
|
export default <D extends Record<string, any> = {}>({
|
|
725
725
|
autoResetExpanded = false,
|
|
726
|
+
columnResizeMode = 'onEnd',
|
|
726
727
|
enableColumnActions = true,
|
|
727
728
|
enableColumnFilters = true,
|
|
729
|
+
enableColumnResizing = false,
|
|
728
730
|
enableDensePaddingToggle = true,
|
|
729
731
|
enableExpandAll = true,
|
|
730
732
|
enableFilters = true,
|
|
@@ -751,7 +753,9 @@ export default <D extends Record<string, any> = {}>({
|
|
|
751
753
|
}: MaterialReactTableProps<D>) => (
|
|
752
754
|
<MRT_TableRoot
|
|
753
755
|
autoResetExpanded={autoResetExpanded}
|
|
756
|
+
columnResizeMode={columnResizeMode}
|
|
754
757
|
enableColumnActions={enableColumnActions}
|
|
758
|
+
enableColumnResizing={enableColumnResizing}
|
|
755
759
|
enableColumnFilters={enableColumnFilters}
|
|
756
760
|
enableDensePaddingToggle={enableDensePaddingToggle}
|
|
757
761
|
enableExpandAll={enableExpandAll}
|
|
@@ -60,6 +60,8 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
60
60
|
}
|
|
61
61
|
{...tableCellProps}
|
|
62
62
|
sx={{
|
|
63
|
+
maxWidth: `min(${column.getWidth()}px, fit-content)`,
|
|
64
|
+
minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
|
|
63
65
|
p: isDensePadding
|
|
64
66
|
? column.columnDefType === 'display'
|
|
65
67
|
? '0 0.5rem'
|
|
@@ -76,6 +78,7 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
76
78
|
isDensePadding || (enablePinning && getIsSomeColumnsPinned())
|
|
77
79
|
? 'nowrap'
|
|
78
80
|
: 'normal',
|
|
81
|
+
width: column.getWidth(),
|
|
79
82
|
//@ts-ignore
|
|
80
83
|
...tableCellProps?.sx,
|
|
81
84
|
}}
|
|
@@ -46,8 +46,11 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
46
46
|
0.05,
|
|
47
47
|
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
48
48
|
fontWeight: 'bold',
|
|
49
|
+
maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
|
|
50
|
+
minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
|
|
49
51
|
p: isDensePadding ? '0.5rem' : '1rem',
|
|
50
52
|
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
|
53
|
+
width: column.getWidth(),
|
|
51
54
|
verticalAlign: 'text-top',
|
|
52
55
|
//@ts-ignore
|
|
53
56
|
...tableCellProps?.sx,
|
|
@@ -97,10 +97,10 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
97
97
|
theme.palette.common.white,
|
|
98
98
|
0.05,
|
|
99
99
|
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
100
|
-
boxShadow: `3px 0 6px ${alpha(theme.palette.common.black, 0.1)}`,
|
|
101
100
|
fontWeight: 'bold',
|
|
102
101
|
height: '100%',
|
|
103
|
-
|
|
102
|
+
maxWidth: `min(${column.getWidth()}px, ${column.maxWidth}px)`,
|
|
103
|
+
minWidth: `max(${column.getWidth()}px, ${column.minWidth}px)`,
|
|
104
104
|
p: isDensePadding
|
|
105
105
|
? column.columnDefType === 'display'
|
|
106
106
|
? '0 0.5rem'
|
|
@@ -115,9 +115,11 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
115
115
|
? '0.75rem'
|
|
116
116
|
: '1.25rem',
|
|
117
117
|
pb: column.columnDefType === 'display' ? 0 : undefined,
|
|
118
|
+
overflow: 'visible',
|
|
118
119
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
119
120
|
verticalAlign: 'text-top',
|
|
120
121
|
width: header.getWidth(),
|
|
122
|
+
zIndex: column.getIsResizing() ? 2 : 1,
|
|
121
123
|
//@ts-ignore
|
|
122
124
|
...tableCellProps?.sx,
|
|
123
125
|
})}
|
|
@@ -148,7 +150,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
148
150
|
}}
|
|
149
151
|
>
|
|
150
152
|
{headerElement}
|
|
151
|
-
{column.columnDefType
|
|
153
|
+
{column.columnDefType === 'data' && column.getCanSort() && (
|
|
152
154
|
<Tooltip arrow placement="top" title={sortTooltip}>
|
|
153
155
|
<TableSortLabel
|
|
154
156
|
aria-label={sortTooltip}
|
|
@@ -161,7 +163,7 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
161
163
|
/>
|
|
162
164
|
</Tooltip>
|
|
163
165
|
)}
|
|
164
|
-
{column.columnDefType
|
|
166
|
+
{column.columnDefType === 'data' &&
|
|
165
167
|
enableColumnFilters &&
|
|
166
168
|
!!column.getCanColumnFilter() && (
|
|
167
169
|
<Tooltip arrow placement="top" title={filterTooltip}>
|
|
@@ -192,59 +194,56 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, tableInstance }) => {
|
|
|
192
194
|
</Tooltip>
|
|
193
195
|
)}
|
|
194
196
|
</Box>
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
<MRT_ToggleColumnActionMenuButton
|
|
202
|
-
header={header}
|
|
203
|
-
tableInstance={tableInstance}
|
|
204
|
-
/>
|
|
205
|
-
)}
|
|
206
|
-
{enableColumnResizing && column.columnDefType !== 'group' && (
|
|
207
|
-
<Divider
|
|
208
|
-
flexItem
|
|
209
|
-
orientation="vertical"
|
|
210
|
-
onDoubleClick={() => header.resetSize()}
|
|
211
|
-
sx={(theme: Theme) => ({
|
|
212
|
-
borderRightWidth: '2px',
|
|
213
|
-
borderRadius: '2px',
|
|
214
|
-
maxHeight: '2rem',
|
|
215
|
-
cursor: 'col-resize',
|
|
216
|
-
userSelect: 'none',
|
|
217
|
-
touchAction: 'none',
|
|
218
|
-
'&:active': {
|
|
219
|
-
backgroundColor: theme.palette.secondary.dark,
|
|
220
|
-
opacity: 1,
|
|
221
|
-
},
|
|
222
|
-
})}
|
|
223
|
-
{...(header.getResizerProps((props: ColumnResizerProps) => ({
|
|
224
|
-
...props,
|
|
225
|
-
style: {
|
|
226
|
-
transform: column.getIsResizing()
|
|
227
|
-
? `translateX(${
|
|
228
|
-
getState().columnSizingInfo.deltaOffset
|
|
229
|
-
}px)`
|
|
230
|
-
: '',
|
|
231
|
-
},
|
|
232
|
-
})) as any)}
|
|
197
|
+
{(enableColumnActions || column.enableColumnActions) &&
|
|
198
|
+
column.enableColumnActions !== false &&
|
|
199
|
+
column.columnDefType !== 'group' && (
|
|
200
|
+
<MRT_ToggleColumnActionMenuButton
|
|
201
|
+
header={header}
|
|
202
|
+
tableInstance={tableInstance}
|
|
233
203
|
/>
|
|
234
204
|
)}
|
|
235
|
-
|
|
205
|
+
{column.getCanResize() && (
|
|
206
|
+
<Divider
|
|
207
|
+
flexItem
|
|
208
|
+
orientation="vertical"
|
|
209
|
+
onDoubleClick={() => header.resetSize()}
|
|
210
|
+
sx={(theme: Theme) => ({
|
|
211
|
+
borderRadius: '2px',
|
|
212
|
+
borderRightWidth: '2px',
|
|
213
|
+
cursor: 'col-resize',
|
|
214
|
+
height:
|
|
215
|
+
showFilters && column.columnDefType === 'data'
|
|
216
|
+
? '4rem'
|
|
217
|
+
: '2rem',
|
|
218
|
+
opacity: 0.8,
|
|
219
|
+
position: 'absolute',
|
|
220
|
+
right: '1px',
|
|
221
|
+
touchAction: 'none',
|
|
222
|
+
transition: 'all 0.2s ease-in-out',
|
|
223
|
+
userSelect: 'none',
|
|
224
|
+
zIndex: 2000,
|
|
225
|
+
'&:active': {
|
|
226
|
+
backgroundColor: theme.palette.info.main,
|
|
227
|
+
opacity: 1,
|
|
228
|
+
},
|
|
229
|
+
})}
|
|
230
|
+
{...(header.getResizerProps((props: ColumnResizerProps) => ({
|
|
231
|
+
...props,
|
|
232
|
+
style: {
|
|
233
|
+
transform: column.getIsResizing()
|
|
234
|
+
? `translateX(${getState().columnSizingInfo.deltaOffset}px)`
|
|
235
|
+
: '',
|
|
236
|
+
},
|
|
237
|
+
})) as any)}
|
|
238
|
+
/>
|
|
239
|
+
)}
|
|
236
240
|
</Box>
|
|
237
241
|
)}
|
|
238
|
-
{column.columnDefType === 'data' &&
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
header={header}
|
|
244
|
-
tableInstance={tableInstance}
|
|
245
|
-
/>
|
|
246
|
-
</Collapse>
|
|
247
|
-
)}
|
|
242
|
+
{column.columnDefType === 'data' && column.getCanColumnFilter() && (
|
|
243
|
+
<Collapse in={showFilters}>
|
|
244
|
+
<MRT_FilterTextField header={header} tableInstance={tableInstance} />
|
|
245
|
+
</Collapse>
|
|
246
|
+
)}
|
|
248
247
|
</TableCell>
|
|
249
248
|
);
|
|
250
249
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { TableRow } from '@mui/material';
|
|
1
|
+
import React, { CSSProperties, FC } from 'react';
|
|
2
|
+
import { alpha, 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
|
|
|
@@ -24,7 +24,16 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, tableInstance }) => {
|
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
return (
|
|
27
|
-
<TableRow
|
|
27
|
+
<TableRow
|
|
28
|
+
{...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
|
+
}
|
|
36
|
+
>
|
|
28
37
|
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
29
38
|
<MRT_TableHeadCell
|
|
30
39
|
header={header}
|
package/src/icons.ts
CHANGED
|
@@ -19,6 +19,7 @@ import FullscreenIcon from '@mui/icons-material/Fullscreen';
|
|
|
19
19
|
import MoreHorizIcon from '@mui/icons-material/MoreHoriz';
|
|
20
20
|
import MoreVertIcon from '@mui/icons-material/MoreVert';
|
|
21
21
|
import PushPinIcon from '@mui/icons-material/PushPin';
|
|
22
|
+
import RestartAltIcon from '@mui/icons-material/RestartAlt';
|
|
22
23
|
import SaveIcon from '@mui/icons-material/Save';
|
|
23
24
|
import SearchIcon from '@mui/icons-material/Search';
|
|
24
25
|
import SearchOffIcon from '@mui/icons-material/SearchOff';
|
|
@@ -48,6 +49,7 @@ export interface MRT_Icons {
|
|
|
48
49
|
MoreHorizIcon: any;
|
|
49
50
|
MoreVertIcon: any;
|
|
50
51
|
PushPinIcon: any;
|
|
52
|
+
RestartAltIcon: any;
|
|
51
53
|
SaveIcon: any;
|
|
52
54
|
SearchIcon: any;
|
|
53
55
|
SearchOffIcon: any;
|
|
@@ -78,6 +80,7 @@ export const MRT_Default_Icons: MRT_Icons = {
|
|
|
78
80
|
MoreHorizIcon,
|
|
79
81
|
MoreVertIcon,
|
|
80
82
|
PushPinIcon,
|
|
83
|
+
RestartAltIcon,
|
|
81
84
|
SaveIcon,
|
|
82
85
|
SearchIcon,
|
|
83
86
|
SearchOffIcon,
|
package/src/localization.ts
CHANGED
|
@@ -32,6 +32,7 @@ export interface MRT_Localization {
|
|
|
32
32
|
hideColumn: string;
|
|
33
33
|
pinToLeft: string;
|
|
34
34
|
pinToRight: string;
|
|
35
|
+
resetColumnSize: string;
|
|
35
36
|
rowActions: string;
|
|
36
37
|
rowNumber: string;
|
|
37
38
|
rowNumbers: string;
|
|
@@ -92,6 +93,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
92
93
|
hideColumn: 'Hide {column} column',
|
|
93
94
|
pinToLeft: 'Pin to left',
|
|
94
95
|
pinToRight: 'Pin to right',
|
|
96
|
+
resetColumnSize: 'Reset column size',
|
|
95
97
|
rowActions: 'Row Actions',
|
|
96
98
|
rowNumber: '#',
|
|
97
99
|
rowNumbers: 'Row Numbers',
|
|
@@ -35,9 +35,10 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
35
35
|
setColumnOrder,
|
|
36
36
|
options: {
|
|
37
37
|
enableColumnFilters,
|
|
38
|
-
|
|
38
|
+
enableColumnResizing,
|
|
39
39
|
enableGrouping,
|
|
40
40
|
enableHiding,
|
|
41
|
+
enablePinning,
|
|
41
42
|
enableSorting,
|
|
42
43
|
icons: {
|
|
43
44
|
ArrowRightIcon,
|
|
@@ -48,6 +49,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
48
49
|
FilterListOffIcon,
|
|
49
50
|
PushPinIcon,
|
|
50
51
|
SortIcon,
|
|
52
|
+
RestartAltIcon,
|
|
51
53
|
VisibilityOffIcon,
|
|
52
54
|
},
|
|
53
55
|
idPrefix,
|
|
@@ -58,7 +60,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
58
60
|
|
|
59
61
|
const { column } = header;
|
|
60
62
|
|
|
61
|
-
const {
|
|
63
|
+
const { columnSizing, columnVisibility, isDensePadding } = getState();
|
|
62
64
|
|
|
63
65
|
const [filterMenuAnchorEl, setFilterMenuAnchorEl] =
|
|
64
66
|
useState<null | HTMLElement>(null);
|
|
@@ -81,6 +83,11 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
81
83
|
setAnchorEl(null);
|
|
82
84
|
};
|
|
83
85
|
|
|
86
|
+
const handleResetColumnSize = () => {
|
|
87
|
+
column.resetSize();
|
|
88
|
+
setAnchorEl(null);
|
|
89
|
+
};
|
|
90
|
+
|
|
84
91
|
const handleHideColumn = () => {
|
|
85
92
|
column.toggleVisibility(false);
|
|
86
93
|
setAnchorEl(null);
|
|
@@ -263,7 +270,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
263
270
|
{enablePinning &&
|
|
264
271
|
column.getCanPin() && [
|
|
265
272
|
<MenuItem
|
|
266
|
-
disabled={column.getIsPinned() === 'left'}
|
|
273
|
+
disabled={column.getIsPinned() === 'left' || !column.getCanPin()}
|
|
267
274
|
key={0}
|
|
268
275
|
onClick={() => handlePinColumn('left')}
|
|
269
276
|
sx={commonMenuItemStyles}
|
|
@@ -276,7 +283,7 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
276
283
|
</Box>
|
|
277
284
|
</MenuItem>,
|
|
278
285
|
<MenuItem
|
|
279
|
-
disabled={column.getIsPinned() === 'right'}
|
|
286
|
+
disabled={column.getIsPinned() === 'right' || !column.getCanPin()}
|
|
280
287
|
key={0}
|
|
281
288
|
onClick={() => handlePinColumn('right')}
|
|
282
289
|
sx={commonMenuItemStyles}
|
|
@@ -303,6 +310,21 @@ export const MRT_ColumnActionMenu: FC<Props> = ({
|
|
|
303
310
|
</Box>
|
|
304
311
|
</MenuItem>,
|
|
305
312
|
]}
|
|
313
|
+
{enableColumnResizing && [
|
|
314
|
+
<MenuItem
|
|
315
|
+
disabled={!column.getCanResize() || !columnSizing[column.id]}
|
|
316
|
+
key={0}
|
|
317
|
+
onClick={handleResetColumnSize}
|
|
318
|
+
sx={commonMenuItemStyles}
|
|
319
|
+
>
|
|
320
|
+
<Box sx={commonListItemStyles}>
|
|
321
|
+
<ListItemIcon>
|
|
322
|
+
<RestartAltIcon />
|
|
323
|
+
</ListItemIcon>
|
|
324
|
+
{localization.resetColumnSize}
|
|
325
|
+
</Box>
|
|
326
|
+
</MenuItem>,
|
|
327
|
+
]}
|
|
306
328
|
{enableHiding && [
|
|
307
329
|
<MenuItem
|
|
308
330
|
disabled={column.enableHiding === false}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import React, { FC, useEffect, useState } from 'react';
|
|
1
|
+
import React, { CSSProperties, FC, useEffect, useState } from 'react';
|
|
2
2
|
import { alpha, Box, TableContainer, Theme } from '@mui/material';
|
|
3
|
-
import { SystemStyleObject } from '@mui/material/node_modules/@mui/system';
|
|
4
3
|
import { MRT_TableInstance } from '..';
|
|
5
4
|
import { MRT_Table } from './MRT_Table';
|
|
6
5
|
|
|
@@ -12,10 +11,10 @@ const commonBoxStyles = ({
|
|
|
12
11
|
pinned?: 'left' | 'right';
|
|
13
12
|
theme: Theme;
|
|
14
13
|
visible?: boolean;
|
|
15
|
-
}):
|
|
14
|
+
}): CSSProperties => ({
|
|
16
15
|
display: 'grid',
|
|
17
16
|
minWidth: visible ? '200px' : 0,
|
|
18
|
-
overflowX: 'auto',
|
|
17
|
+
overflowX: pinned ? 'scroll' : 'auto',
|
|
19
18
|
boxShadow:
|
|
20
19
|
pinned === 'left'
|
|
21
20
|
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
@@ -82,10 +82,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
82
82
|
props.globalFilterType ?? MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
83
83
|
);
|
|
84
84
|
|
|
85
|
-
const table = useMemo(
|
|
86
|
-
() => createTable<{ Row: D }>(),
|
|
87
|
-
[],
|
|
88
|
-
) as unknown as Table<D>;
|
|
85
|
+
const table = useMemo(() => createTable() as unknown as Table<D>, []);
|
|
89
86
|
|
|
90
87
|
const displayColumns = useMemo(
|
|
91
88
|
() =>
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
2
|
import { MRT_ColumnDef, MRT_FilterType } from '.';
|
|
3
3
|
import { MRT_FILTER_TYPE } from './enums';
|
|
4
|
+
import { defaultFilterFNs } from './filtersFNs';
|
|
4
5
|
|
|
5
6
|
export const getAllLeafColumnDefs = (
|
|
6
7
|
columns: MRT_ColumnDef[],
|
|
@@ -40,7 +41,10 @@ export const createDataColumn = <D extends Record<string, any> = {}>(
|
|
|
40
41
|
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
41
42
|
): ColumnDef<D> => // @ts-ignore
|
|
42
43
|
table.createDataColumn(column.id, {
|
|
43
|
-
|
|
44
|
+
filterFn:
|
|
45
|
+
currentFilterTypes[column.id] instanceof Function
|
|
46
|
+
? currentFilterTypes[column.id]
|
|
47
|
+
: defaultFilterFNs[currentFilterTypes[column.id] as MRT_FILTER_TYPE],
|
|
44
48
|
...column,
|
|
45
49
|
}) as any;
|
|
46
50
|
|