material-react-table 0.7.0-alpha.9 → 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/README.md +3 -5
- package/dist/MaterialReactTable.d.ts +65 -46
- package/dist/buttons/{MRT_ToggleSearchButton.d.ts → MRT_ToggleGlobalFilterButton.d.ts} +1 -1
- package/dist/icons.d.ts +1 -0
- package/dist/localization.d.ts +4 -0
- package/dist/material-react-table.cjs.development.js +279 -187
- 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 +282 -190
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +2 -2
- package/dist/utils.d.ts +5 -5
- package/package.json +5 -5
- package/src/MaterialReactTable.tsx +107 -57
- package/src/body/MRT_TableBodyCell.tsx +5 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -1
- package/src/buttons/MRT_FullScreenToggleButton.tsx +13 -4
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +0 -1
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +13 -4
- package/src/buttons/MRT_ToggleFiltersButton.tsx +13 -4
- package/src/buttons/{MRT_ToggleSearchButton.tsx → MRT_ToggleGlobalFilterButton.tsx} +14 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
- package/src/footer/MRT_TableFooterCell.tsx +3 -0
- package/src/head/MRT_TableHeadCell.tsx +60 -62
- package/src/head/MRT_TableHeadRow.tsx +12 -3
- package/src/icons.ts +3 -0
- package/src/inputs/MRT_EditCellTextField.tsx +2 -5
- package/src/inputs/MRT_FilterTextField.tsx +2 -2
- package/src/inputs/MRT_SearchTextField.tsx +6 -6
- package/src/localization.ts +8 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +29 -7
- package/src/menus/MRT_FilterTypeMenu.tsx +5 -8
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +7 -7
- package/src/table/MRT_Table.tsx +5 -5
- package/src/table/MRT_TableContainer.tsx +6 -7
- package/src/table/MRT_TablePaper.tsx +9 -13
- package/src/table/MRT_TableRoot.tsx +97 -83
- package/src/toolbar/MRT_ToolbarBottom.tsx +2 -2
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +8 -9
- package/src/toolbar/MRT_ToolbarTop.tsx +2 -2
- package/src/utils.ts +15 -11
|
@@ -12,7 +12,7 @@ interface Props {
|
|
|
12
12
|
export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
13
13
|
const {
|
|
14
14
|
getState,
|
|
15
|
-
options: {
|
|
15
|
+
options: { enableToolbarBottom, enableToolbarTop, muiTablePaperProps },
|
|
16
16
|
} = tableInstance;
|
|
17
17
|
|
|
18
18
|
const { isFullScreen } = getState();
|
|
@@ -21,8 +21,10 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
21
21
|
if (typeof window !== 'undefined') {
|
|
22
22
|
if (isFullScreen) {
|
|
23
23
|
document.body.style.overflow = 'hidden';
|
|
24
|
+
document.body.style.height = '100vh';
|
|
24
25
|
} else {
|
|
25
26
|
document.body.style.overflow = 'auto';
|
|
27
|
+
document.body.style.height = 'auto';
|
|
26
28
|
}
|
|
27
29
|
}
|
|
28
30
|
}, [isFullScreen]);
|
|
@@ -41,23 +43,17 @@ export const MRT_TablePaper: FC<Props> = ({ tableInstance }) => {
|
|
|
41
43
|
...tablePaperProps?.sx,
|
|
42
44
|
}}
|
|
43
45
|
style={{
|
|
44
|
-
height: isFullScreen ? '
|
|
45
|
-
left: isFullScreen ? '0' : undefined,
|
|
46
|
+
height: isFullScreen ? '100vh' : undefined,
|
|
46
47
|
margin: isFullScreen ? '0' : undefined,
|
|
47
|
-
maxHeight: isFullScreen ? '
|
|
48
|
-
maxWidth: isFullScreen ? '
|
|
49
|
-
|
|
50
|
-
position: isFullScreen ? 'fixed' : undefined,
|
|
51
|
-
right: isFullScreen ? '0' : undefined,
|
|
52
|
-
top: isFullScreen ? '0' : undefined,
|
|
48
|
+
maxHeight: isFullScreen ? '100vh' : undefined,
|
|
49
|
+
maxWidth: isFullScreen ? '100vw' : undefined,
|
|
50
|
+
padding: isFullScreen ? '0' : undefined,
|
|
53
51
|
width: isFullScreen ? '100vw' : undefined,
|
|
54
|
-
zIndex: isFullScreen ? 1200 : 1,
|
|
55
|
-
bottom: isFullScreen ? '0' : undefined,
|
|
56
52
|
}}
|
|
57
53
|
>
|
|
58
|
-
{
|
|
54
|
+
{enableToolbarTop && <MRT_ToolbarTop tableInstance={tableInstance} />}
|
|
59
55
|
<MRT_TableContainer tableInstance={tableInstance} />
|
|
60
|
-
{
|
|
56
|
+
{enableToolbarBottom && (
|
|
61
57
|
<MRT_ToolbarBottom tableInstance={tableInstance} />
|
|
62
58
|
)}
|
|
63
59
|
</Paper>
|
|
@@ -1,23 +1,20 @@
|
|
|
1
|
+
import React, { useEffect, useMemo, useState } from 'react';
|
|
1
2
|
import {
|
|
2
|
-
columnFilterRowsFn,
|
|
3
|
-
createTable,
|
|
4
|
-
expandRowsFn,
|
|
5
|
-
functionalUpdate,
|
|
6
|
-
globalFilterRowsFn,
|
|
7
|
-
groupRowsFn,
|
|
8
|
-
paginateRowsFn,
|
|
9
3
|
PaginationState,
|
|
10
|
-
sortRowsFn,
|
|
11
4
|
Table,
|
|
12
|
-
|
|
5
|
+
createTable,
|
|
6
|
+
functionalUpdate,
|
|
7
|
+
getColumnFilteredRowModelSync,
|
|
8
|
+
getExpandedRowModel,
|
|
9
|
+
getGlobalFilteredRowModelSync,
|
|
10
|
+
getGroupedRowModelSync,
|
|
11
|
+
getPaginationRowModel,
|
|
12
|
+
getSortedRowModelSync,
|
|
13
|
+
useTableInstance,
|
|
14
|
+
getCoreRowModelSync,
|
|
15
|
+
ColumnDef,
|
|
13
16
|
} from '@tanstack/react-table';
|
|
14
|
-
import
|
|
15
|
-
import {
|
|
16
|
-
MRT_ColumnInterface,
|
|
17
|
-
MRT_FilterType,
|
|
18
|
-
MRT_Row,
|
|
19
|
-
MRT_TableInstance,
|
|
20
|
-
} from '..';
|
|
17
|
+
import { MRT_ColumnDef, MRT_FilterType, MRT_Row, MRT_TableInstance } from '..';
|
|
21
18
|
import { MRT_ExpandAllButton } from '../buttons/MRT_ExpandAllButton';
|
|
22
19
|
import { MRT_ExpandButton } from '../buttons/MRT_ExpandButton';
|
|
23
20
|
import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMenuButton';
|
|
@@ -32,14 +29,18 @@ import {
|
|
|
32
29
|
} from '../utils';
|
|
33
30
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
34
31
|
import { MRT_FILTER_TYPE } from '../enums';
|
|
32
|
+
import { Box, Dialog, Grow } from '@mui/material';
|
|
35
33
|
|
|
36
34
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
37
35
|
props: MaterialReactTableProps<D>,
|
|
38
36
|
) => {
|
|
39
|
-
const idPrefix =
|
|
40
|
-
|
|
37
|
+
const [idPrefix, setIdPrefix] = useState(props.idPrefix);
|
|
38
|
+
useEffect(
|
|
39
|
+
() =>
|
|
40
|
+
setIdPrefix(props.idPrefix ?? Math.random().toString(36).substring(2, 9)),
|
|
41
41
|
[props.idPrefix],
|
|
42
42
|
);
|
|
43
|
+
|
|
43
44
|
const [currentEditingRow, setCurrentEditingRow] = useState<MRT_Row | null>(
|
|
44
45
|
null,
|
|
45
46
|
);
|
|
@@ -52,10 +53,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
52
53
|
const [showFilters, setShowFilters] = useState(
|
|
53
54
|
props.initialState?.showFilters ?? false,
|
|
54
55
|
);
|
|
55
|
-
const [
|
|
56
|
-
props.initialState?.
|
|
56
|
+
const [showGlobalFilter, setShowGlobalFilter] = useState(
|
|
57
|
+
props.initialState?.showGlobalFilter ?? false,
|
|
57
58
|
);
|
|
58
|
-
|
|
59
59
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
60
60
|
pageIndex: props.initialState?.pagination?.pageIndex ?? 0,
|
|
61
61
|
pageSize: props.initialState?.pagination?.pageSize ?? 10,
|
|
@@ -67,16 +67,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
67
67
|
}>(() =>
|
|
68
68
|
Object.assign(
|
|
69
69
|
{},
|
|
70
|
-
...getAllLeafColumnDefs(props.columns as
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}),
|
|
79
|
-
),
|
|
70
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
|
|
71
|
+
[c.id as string]:
|
|
72
|
+
c.filter ??
|
|
73
|
+
props?.initialState?.columnFilters?.find((cf) => cf.id === c.id) ??
|
|
74
|
+
(!!c.filterSelectOptions?.length
|
|
75
|
+
? MRT_FILTER_TYPE.EQUALS
|
|
76
|
+
: MRT_FILTER_TYPE.BEST_MATCH),
|
|
77
|
+
})),
|
|
80
78
|
),
|
|
81
79
|
);
|
|
82
80
|
|
|
@@ -84,10 +82,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
84
82
|
props.globalFilterType ?? MRT_FILTER_TYPE.BEST_MATCH_FIRST,
|
|
85
83
|
);
|
|
86
84
|
|
|
87
|
-
const table = useMemo(
|
|
88
|
-
() => createTable<{ Row: D }>(),
|
|
89
|
-
[],
|
|
90
|
-
) as unknown as Table<D>;
|
|
85
|
+
const table = useMemo(() => createTable() as unknown as Table<D>, []);
|
|
91
86
|
|
|
92
87
|
const displayColumns = useMemo(
|
|
93
88
|
() =>
|
|
@@ -96,7 +91,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
96
91
|
createDisplayColumn(table, {
|
|
97
92
|
Cell: ({ cell }) => (
|
|
98
93
|
<MRT_ToggleRowActionMenuButton
|
|
99
|
-
row={cell.row as
|
|
94
|
+
row={cell.row as MRT_Row}
|
|
100
95
|
tableInstance={tableInstance}
|
|
101
96
|
/>
|
|
102
97
|
),
|
|
@@ -109,7 +104,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
109
104
|
createDisplayColumn(table, {
|
|
110
105
|
Cell: ({ cell }) => (
|
|
111
106
|
<MRT_ExpandButton
|
|
112
|
-
row={cell.row as
|
|
107
|
+
row={cell.row as MRT_Row}
|
|
113
108
|
tableInstance={tableInstance}
|
|
114
109
|
/>
|
|
115
110
|
),
|
|
@@ -126,7 +121,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
126
121
|
createDisplayColumn(table, {
|
|
127
122
|
Cell: ({ cell }) => (
|
|
128
123
|
<MRT_SelectCheckbox
|
|
129
|
-
row={cell.row as
|
|
124
|
+
row={cell.row as MRT_Row}
|
|
130
125
|
tableInstance={tableInstance}
|
|
131
126
|
/>
|
|
132
127
|
),
|
|
@@ -151,16 +146,16 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
151
146
|
}),
|
|
152
147
|
].filter(Boolean),
|
|
153
148
|
[
|
|
154
|
-
|
|
149
|
+
props.enableEditing,
|
|
155
150
|
props.enableExpandAll,
|
|
156
151
|
props.enableExpanded,
|
|
157
|
-
props.enableRowActions,
|
|
158
152
|
props.enableGrouping,
|
|
159
|
-
props.
|
|
153
|
+
props.enableRowActions,
|
|
160
154
|
props.enableRowNumbers,
|
|
161
155
|
props.enableRowSelection,
|
|
162
156
|
props.enableSelectAll,
|
|
163
157
|
props.localization,
|
|
158
|
+
table,
|
|
164
159
|
],
|
|
165
160
|
);
|
|
166
161
|
|
|
@@ -173,21 +168,21 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
173
168
|
? createGroup(table, column, currentFilterTypes)
|
|
174
169
|
: createDataColumn(table, column, currentFilterTypes),
|
|
175
170
|
),
|
|
176
|
-
] as
|
|
171
|
+
] as ColumnDef<D>[]),
|
|
177
172
|
[table, props.columns, currentFilterTypes],
|
|
178
173
|
);
|
|
179
174
|
|
|
180
|
-
const data = useMemo(
|
|
175
|
+
const data: D['Row'][] = useMemo(
|
|
181
176
|
() =>
|
|
182
177
|
props.isLoading && !props.data.length
|
|
183
|
-
? [...Array(10).fill(null)].map((
|
|
178
|
+
? [...Array(10).fill(null)].map(() =>
|
|
184
179
|
Object.assign(
|
|
185
180
|
{},
|
|
186
|
-
...getAllLeafColumnDefs(
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
181
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
|
182
|
+
(c) => ({
|
|
183
|
+
[c.id]: null,
|
|
184
|
+
}),
|
|
185
|
+
),
|
|
191
186
|
),
|
|
192
187
|
)
|
|
193
188
|
: props.data,
|
|
@@ -195,45 +190,64 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
195
190
|
);
|
|
196
191
|
|
|
197
192
|
//@ts-ignore
|
|
198
|
-
const tableInstance: MRT_TableInstance<{}> =
|
|
199
|
-
...
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
193
|
+
const tableInstance: MRT_TableInstance<{}> = {
|
|
194
|
+
...useTableInstance(table, {
|
|
195
|
+
//@ts-ignore
|
|
196
|
+
filterTypes: defaultFilterFNs,
|
|
197
|
+
getColumnFilteredRowModel: getColumnFilteredRowModelSync(),
|
|
198
|
+
getCoreRowModel: getCoreRowModelSync(),
|
|
199
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
200
|
+
getGlobalFilteredRowModel: getGlobalFilteredRowModelSync(),
|
|
201
|
+
getGroupedRowModel: getGroupedRowModelSync(),
|
|
202
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
203
|
+
getSortedRowModel: getSortedRowModelSync(),
|
|
204
|
+
getSubRows: (originalRow: D) => originalRow.subRows,
|
|
205
|
+
globalFilterType: currentGlobalFilterType,
|
|
206
|
+
idPrefix,
|
|
207
|
+
onPaginationChange: (updater: any) =>
|
|
208
|
+
setPagination((old) => functionalUpdate(updater, old)),
|
|
209
|
+
...props,
|
|
210
|
+
columns,
|
|
211
|
+
data,
|
|
212
|
+
state: {
|
|
213
|
+
currentEditingRow,
|
|
214
|
+
currentFilterTypes,
|
|
215
|
+
currentGlobalFilterType,
|
|
216
|
+
isDensePadding,
|
|
217
|
+
isFullScreen,
|
|
218
|
+
//@ts-ignore
|
|
219
|
+
pagination,
|
|
220
|
+
showFilters,
|
|
221
|
+
showGlobalFilter,
|
|
222
|
+
...props.state,
|
|
223
|
+
},
|
|
224
|
+
}),
|
|
215
225
|
setCurrentEditingRow,
|
|
216
226
|
setCurrentFilterTypes,
|
|
217
227
|
setCurrentGlobalFilterType,
|
|
218
228
|
setIsDensePadding,
|
|
219
229
|
setIsFullScreen,
|
|
220
230
|
setShowFilters,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
state: {
|
|
224
|
-
...props.initialState,
|
|
225
|
-
currentEditingRow,
|
|
226
|
-
currentFilterTypes,
|
|
227
|
-
currentGlobalFilterType,
|
|
228
|
-
isDensePadding,
|
|
229
|
-
isFullScreen,
|
|
230
|
-
//@ts-ignore
|
|
231
|
-
pagination,
|
|
232
|
-
showFilters,
|
|
233
|
-
showSearch,
|
|
234
|
-
...props.state,
|
|
235
|
-
},
|
|
236
|
-
});
|
|
231
|
+
setShowGlobalFilter,
|
|
232
|
+
};
|
|
237
233
|
|
|
238
|
-
return
|
|
234
|
+
return (
|
|
235
|
+
<>
|
|
236
|
+
<Dialog
|
|
237
|
+
TransitionComponent={Grow}
|
|
238
|
+
PaperComponent={Box}
|
|
239
|
+
disablePortal
|
|
240
|
+
fullScreen
|
|
241
|
+
keepMounted={false}
|
|
242
|
+
onClose={() => tableInstance.setIsFullScreen(false)}
|
|
243
|
+
open={tableInstance.getState().isFullScreen}
|
|
244
|
+
transitionDuration={400}
|
|
245
|
+
>
|
|
246
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
247
|
+
</Dialog>
|
|
248
|
+
{!tableInstance.getState().isFullScreen && (
|
|
249
|
+
<MRT_TablePaper tableInstance={tableInstance} />
|
|
250
|
+
)}
|
|
251
|
+
</>
|
|
252
|
+
);
|
|
239
253
|
};
|
|
@@ -15,7 +15,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
15
15
|
const {
|
|
16
16
|
getState,
|
|
17
17
|
options: {
|
|
18
|
-
|
|
18
|
+
enableToolbarInternalActions,
|
|
19
19
|
idPrefix,
|
|
20
20
|
enablePagination,
|
|
21
21
|
muiTableToolbarBottomProps,
|
|
@@ -51,7 +51,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
|
|
|
51
51
|
<Box
|
|
52
52
|
sx={{ display: 'flex', justifyContent: 'space-between', width: '100%' }}
|
|
53
53
|
>
|
|
54
|
-
{
|
|
54
|
+
{enableToolbarInternalActions && positionToolbarActions === 'bottom' ? (
|
|
55
55
|
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
56
56
|
) : (
|
|
57
57
|
<span />
|
|
@@ -4,7 +4,7 @@ import { MRT_FullScreenToggleButton } from '../buttons/MRT_FullScreenToggleButto
|
|
|
4
4
|
import { MRT_ShowHideColumnsButton } from '../buttons/MRT_ShowHideColumnsButton';
|
|
5
5
|
import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingButton';
|
|
6
6
|
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
7
|
-
import {
|
|
7
|
+
import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
|
|
8
8
|
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
10
|
interface Props {
|
|
@@ -15,10 +15,11 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
|
15
15
|
const {
|
|
16
16
|
options: {
|
|
17
17
|
enableColumnFilters,
|
|
18
|
-
enableHiding,
|
|
19
18
|
enableDensePaddingToggle,
|
|
20
|
-
|
|
19
|
+
enableFilters,
|
|
21
20
|
enableFullScreenToggle,
|
|
21
|
+
enableGlobalFilter,
|
|
22
|
+
enableHiding,
|
|
22
23
|
renderToolbarInternalActions,
|
|
23
24
|
},
|
|
24
25
|
} = tableInstance;
|
|
@@ -31,7 +32,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
|
31
32
|
MRT_ShowHideColumnsButton,
|
|
32
33
|
MRT_ToggleDensePaddingButton,
|
|
33
34
|
MRT_ToggleFiltersButton,
|
|
34
|
-
|
|
35
|
+
MRT_ToggleGlobalFilterButton,
|
|
35
36
|
tableInstance,
|
|
36
37
|
})}
|
|
37
38
|
</>
|
|
@@ -42,15 +43,13 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ tableInstance }) => {
|
|
|
42
43
|
<Box
|
|
43
44
|
sx={{
|
|
44
45
|
display: 'flex',
|
|
45
|
-
gap: '0.5rem',
|
|
46
46
|
alignItems: 'center',
|
|
47
|
-
p: '0 0.5rem',
|
|
48
47
|
}}
|
|
49
48
|
>
|
|
50
|
-
{enableGlobalFilter && (
|
|
51
|
-
<
|
|
49
|
+
{enableFilters && enableGlobalFilter && (
|
|
50
|
+
<MRT_ToggleGlobalFilterButton tableInstance={tableInstance} />
|
|
52
51
|
)}
|
|
53
|
-
{enableColumnFilters && (
|
|
52
|
+
{enableFilters && enableColumnFilters && (
|
|
54
53
|
<MRT_ToggleFiltersButton tableInstance={tableInstance} />
|
|
55
54
|
)}
|
|
56
55
|
{enableHiding && (
|
|
@@ -29,7 +29,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
29
29
|
options: {
|
|
30
30
|
enableGlobalFilter,
|
|
31
31
|
enablePagination,
|
|
32
|
-
|
|
32
|
+
enableToolbarInternalActions,
|
|
33
33
|
idPrefix,
|
|
34
34
|
muiTableToolbarTopProps,
|
|
35
35
|
positionPagination,
|
|
@@ -82,7 +82,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ tableInstance }) => {
|
|
|
82
82
|
{enableGlobalFilter && (
|
|
83
83
|
<MRT_SearchTextField tableInstance={tableInstance} />
|
|
84
84
|
)}
|
|
85
|
-
{
|
|
85
|
+
{enableToolbarInternalActions && positionToolbarActions === 'top' && (
|
|
86
86
|
<MRT_ToolbarInternalButtons tableInstance={tableInstance} />
|
|
87
87
|
)}
|
|
88
88
|
</Box>
|
package/src/utils.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import {
|
|
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
|
-
columns:
|
|
7
|
-
):
|
|
8
|
-
let lowestLevelColumns:
|
|
9
|
-
let currentCols:
|
|
7
|
+
columns: MRT_ColumnDef[],
|
|
8
|
+
): MRT_ColumnDef[] => {
|
|
9
|
+
let lowestLevelColumns: MRT_ColumnDef[] = columns;
|
|
10
|
+
let currentCols: MRT_ColumnDef[] | undefined = columns;
|
|
10
11
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
11
|
-
const nextCols:
|
|
12
|
+
const nextCols: MRT_ColumnDef[] = currentCols
|
|
12
13
|
.filter((col) => !!col.columns)
|
|
13
14
|
.map((col) => col.columns)
|
|
14
|
-
.flat() as
|
|
15
|
+
.flat() as MRT_ColumnDef[];
|
|
15
16
|
if (nextCols.every((col) => !col?.columns)) {
|
|
16
17
|
lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
|
|
17
18
|
}
|
|
@@ -22,7 +23,7 @@ export const getAllLeafColumnDefs = (
|
|
|
22
23
|
|
|
23
24
|
export const createGroup = <D extends Record<string, any> = {}>(
|
|
24
25
|
table: Table<D>,
|
|
25
|
-
column:
|
|
26
|
+
column: MRT_ColumnDef<D>,
|
|
26
27
|
currentFilterTypes: { [key: string]: MRT_FilterType },
|
|
27
28
|
): ColumnDef<D> =>
|
|
28
29
|
table.createGroup({
|
|
@@ -36,15 +37,18 @@ export const createGroup = <D extends Record<string, any> = {}>(
|
|
|
36
37
|
|
|
37
38
|
export const createDataColumn = <D extends Record<string, any> = {}>(
|
|
38
39
|
table: Table<D>,
|
|
39
|
-
column:
|
|
40
|
+
column: MRT_ColumnDef<D>,
|
|
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
|
|
|
47
51
|
export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
48
52
|
table: Table<D>,
|
|
49
|
-
column: Omit<
|
|
53
|
+
column: Omit<MRT_ColumnDef<D>, 'header'> & { header?: string },
|
|
50
54
|
): ColumnDef<D> => table.createDisplayColumn(column);
|