material-react-table 0.7.4 → 0.8.0-alpha.1
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 +25 -31
- package/dist/body/MRT_TableBody.d.ts +0 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/body/MRT_TableBodyRow.d.ts +0 -1
- package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/enums.d.ts +3 -3
- package/dist/filtersFNs.d.ts +31 -30
- package/dist/footer/MRT_TableFooter.d.ts +0 -1
- package/dist/head/MRT_TableHead.d.ts +0 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
- package/dist/localization.d.ts +7 -2
- package/dist/material-react-table.cjs.development.js +489 -448
- 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 +492 -451
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/{MRT_FilterTypeMenu.d.ts → MRT_FilterOptionMenu.d.ts} +1 -1
- package/dist/table/MRT_Table.d.ts +0 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
- package/dist/utils.d.ts +6 -6
- package/package.json +24 -24
- package/src/MaterialReactTable.tsx +39 -41
- package/src/body/MRT_TableBody.tsx +3 -11
- package/src/body/MRT_TableBodyCell.tsx +102 -51
- package/src/body/MRT_TableBodyRow.tsx +21 -30
- package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +1 -2
- package/src/enums.ts +3 -3
- package/src/filtersFNs.ts +71 -81
- package/src/footer/MRT_TableFooter.tsx +6 -16
- package/src/footer/MRT_TableFooterCell.tsx +5 -7
- package/src/footer/MRT_TableFooterRow.tsx +5 -8
- package/src/head/MRT_TableHead.tsx +5 -16
- package/src/head/MRT_TableHeadCell.tsx +101 -44
- package/src/head/MRT_TableHeadRow.tsx +8 -15
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/inputs/MRT_FilterTextField.tsx +84 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -2
- package/src/inputs/MRT_SelectCheckbox.tsx +16 -17
- package/src/localization.ts +15 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +9 -8
- package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +54 -49
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -5
- package/src/table/MRT_Table.tsx +8 -19
- package/src/table/MRT_TableContainer.tsx +8 -69
- package/src/table/MRT_TableRoot.tsx +70 -70
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
- package/src/utils.ts +10 -10
|
@@ -1,27 +1,10 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
import {
|
|
1
|
+
import React, { FC, useEffect, useLayoutEffect, useState } from 'react';
|
|
2
|
+
import { TableContainer } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
import { MRT_Table } from './MRT_Table';
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
theme,
|
|
9
|
-
visible,
|
|
10
|
-
}: {
|
|
11
|
-
pinned?: 'left' | 'right';
|
|
12
|
-
theme: Theme;
|
|
13
|
-
visible?: boolean;
|
|
14
|
-
}): CSSProperties => ({
|
|
15
|
-
display: 'grid',
|
|
16
|
-
minWidth: visible ? '200px' : 0,
|
|
17
|
-
overflowX: pinned ? 'scroll' : 'auto',
|
|
18
|
-
boxShadow:
|
|
19
|
-
pinned === 'left'
|
|
20
|
-
? `0 1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
21
|
-
: pinned === 'right'
|
|
22
|
-
? `0 -1px 12px ${alpha(theme.palette.common.black, 0.5)}`
|
|
23
|
-
: 'none',
|
|
24
|
-
});
|
|
6
|
+
const useIsomorphicLayoutEffect =
|
|
7
|
+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
25
8
|
|
|
26
9
|
interface Props {
|
|
27
10
|
tableInstance: MRT_TableInstance;
|
|
@@ -29,20 +12,11 @@ interface Props {
|
|
|
29
12
|
|
|
30
13
|
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
31
14
|
const {
|
|
32
|
-
getCenterTableWidth,
|
|
33
|
-
getIsSomeColumnsPinned,
|
|
34
|
-
getLeftTableWidth,
|
|
35
|
-
getRightTableWidth,
|
|
36
15
|
getState,
|
|
37
|
-
options: {
|
|
38
|
-
enablePinning,
|
|
39
|
-
enableStickyHeader,
|
|
40
|
-
idPrefix,
|
|
41
|
-
muiTableContainerProps,
|
|
42
|
-
},
|
|
16
|
+
options: { enableStickyHeader, idPrefix, muiTableContainerProps },
|
|
43
17
|
} = tableInstance;
|
|
44
18
|
|
|
45
|
-
const { isFullScreen
|
|
19
|
+
const { isFullScreen } = getState();
|
|
46
20
|
|
|
47
21
|
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
|
48
22
|
|
|
@@ -51,7 +25,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
51
25
|
? muiTableContainerProps({ tableInstance })
|
|
52
26
|
: muiTableContainerProps;
|
|
53
27
|
|
|
54
|
-
|
|
28
|
+
useIsomorphicLayoutEffect(() => {
|
|
55
29
|
const topToolbarHeight =
|
|
56
30
|
typeof document !== 'undefined'
|
|
57
31
|
? document?.getElementById(`mrt-${idPrefix}-toolbar-top`)
|
|
@@ -84,42 +58,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
84
58
|
: undefined,
|
|
85
59
|
}}
|
|
86
60
|
>
|
|
87
|
-
{
|
|
88
|
-
<Box
|
|
89
|
-
sx={{
|
|
90
|
-
display: 'grid',
|
|
91
|
-
gridTemplateColumns: `${getLeftTableWidth()}fr ${getCenterTableWidth()}fr ${getRightTableWidth()}fr`,
|
|
92
|
-
}}
|
|
93
|
-
>
|
|
94
|
-
<Box
|
|
95
|
-
sx={(theme: Theme) =>
|
|
96
|
-
commonBoxStyles({
|
|
97
|
-
pinned: 'left',
|
|
98
|
-
theme,
|
|
99
|
-
visible: !!columnPinning.left?.length,
|
|
100
|
-
})
|
|
101
|
-
}
|
|
102
|
-
>
|
|
103
|
-
<MRT_Table pinned="left" tableInstance={tableInstance} />
|
|
104
|
-
</Box>
|
|
105
|
-
<Box sx={(theme: Theme) => commonBoxStyles({ theme })}>
|
|
106
|
-
<MRT_Table pinned="center" tableInstance={tableInstance} />
|
|
107
|
-
</Box>
|
|
108
|
-
<Box
|
|
109
|
-
sx={(theme: Theme) =>
|
|
110
|
-
commonBoxStyles({
|
|
111
|
-
pinned: 'right',
|
|
112
|
-
theme,
|
|
113
|
-
visible: !!columnPinning.right?.length,
|
|
114
|
-
})
|
|
115
|
-
}
|
|
116
|
-
>
|
|
117
|
-
<MRT_Table pinned="right" tableInstance={tableInstance} />
|
|
118
|
-
</Box>
|
|
119
|
-
</Box>
|
|
120
|
-
) : (
|
|
121
|
-
<MRT_Table pinned="none" tableInstance={tableInstance} />
|
|
122
|
-
)}
|
|
61
|
+
<MRT_Table tableInstance={tableInstance} />
|
|
123
62
|
</TableContainer>
|
|
124
63
|
);
|
|
125
64
|
};
|
|
@@ -1,23 +1,23 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
FilterFn,
|
|
3
4
|
PaginationState,
|
|
4
|
-
Table,
|
|
5
5
|
createTable,
|
|
6
6
|
functionalUpdate,
|
|
7
|
-
getColumnFilteredRowModelSync,
|
|
8
7
|
getExpandedRowModel,
|
|
9
|
-
getGlobalFilteredRowModelSync,
|
|
10
|
-
getGroupedRowModelSync,
|
|
11
8
|
getPaginationRowModel,
|
|
12
|
-
getSortedRowModelSync,
|
|
13
9
|
useTableInstance,
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
getGroupedRowModel,
|
|
11
|
+
getSortedRowModel,
|
|
12
|
+
getCoreRowModel,
|
|
13
|
+
getFilteredRowModel,
|
|
14
|
+
ReactTableGenerics,
|
|
15
|
+
getFacetedRowModel,
|
|
16
16
|
} from '@tanstack/react-table';
|
|
17
17
|
import {
|
|
18
18
|
MRT_Cell,
|
|
19
19
|
MRT_ColumnDef,
|
|
20
|
-
|
|
20
|
+
MRT_FilterFn,
|
|
21
21
|
MRT_Row,
|
|
22
22
|
MRT_TableInstance,
|
|
23
23
|
MRT_TableState,
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
getAllLeafColumnDefs,
|
|
36
36
|
} from '../utils';
|
|
37
37
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
38
|
-
import {
|
|
38
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
39
39
|
import { Box, Dialog, Grow } from '@mui/material';
|
|
40
40
|
|
|
41
41
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
@@ -95,30 +95,30 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
95
95
|
const [pagination, setPagination] = useState<PaginationState>({
|
|
96
96
|
pageIndex: initialState?.pagination?.pageIndex ?? 0,
|
|
97
97
|
pageSize: initialState?.pagination?.pageSize ?? 10,
|
|
98
|
-
pageCount: initialState?.pagination?.pageCount
|
|
98
|
+
pageCount: initialState?.pagination?.pageCount,
|
|
99
99
|
});
|
|
100
100
|
|
|
101
|
-
const [
|
|
102
|
-
[key: string]:
|
|
101
|
+
const [currentFilterFns, setCurrentFilterFns] = useState<{
|
|
102
|
+
[key: string]: MRT_FilterFn;
|
|
103
103
|
}>(() =>
|
|
104
104
|
Object.assign(
|
|
105
105
|
{},
|
|
106
106
|
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
|
|
107
107
|
[c.id as string]:
|
|
108
|
-
c.
|
|
109
|
-
initialState?.
|
|
108
|
+
c.filterFn ??
|
|
109
|
+
initialState?.currentFilterFns?.[c.id] ??
|
|
110
110
|
(!!c.filterSelectOptions?.length
|
|
111
|
-
?
|
|
112
|
-
:
|
|
111
|
+
? MRT_FILTER_OPTION.EQUALS
|
|
112
|
+
: MRT_FILTER_OPTION.FUZZY),
|
|
113
113
|
})),
|
|
114
114
|
),
|
|
115
115
|
);
|
|
116
116
|
|
|
117
|
-
const [
|
|
118
|
-
|
|
119
|
-
);
|
|
117
|
+
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] = useState<
|
|
118
|
+
MRT_FILTER_OPTION | FilterFn<ReactTableGenerics> | string | number | symbol
|
|
119
|
+
>(props.globalFilterFn ?? MRT_FILTER_OPTION.FUZZY);
|
|
120
120
|
|
|
121
|
-
const table = useMemo(() => createTable()
|
|
121
|
+
const table = useMemo(() => createTable(), []);
|
|
122
122
|
|
|
123
123
|
const displayColumns = useMemo(
|
|
124
124
|
() =>
|
|
@@ -128,20 +128,19 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
128
128
|
createDisplayColumn(table, {
|
|
129
129
|
Cell: ({ cell }) => (
|
|
130
130
|
<MRT_ToggleRowActionMenuButton
|
|
131
|
-
row={cell.row as
|
|
131
|
+
row={cell.row as any}
|
|
132
132
|
tableInstance={tableInstance}
|
|
133
133
|
/>
|
|
134
134
|
),
|
|
135
135
|
header: props.localization?.actions,
|
|
136
136
|
id: 'mrt-row-actions',
|
|
137
|
-
|
|
138
|
-
width: 60,
|
|
137
|
+
size: 60,
|
|
139
138
|
}),
|
|
140
|
-
(props.
|
|
139
|
+
(props.enableExpanding || props.enableGrouping) &&
|
|
141
140
|
createDisplayColumn(table, {
|
|
142
141
|
Cell: ({ cell }) => (
|
|
143
142
|
<MRT_ExpandButton
|
|
144
|
-
row={cell.row as
|
|
143
|
+
row={cell.row as any}
|
|
145
144
|
tableInstance={tableInstance}
|
|
146
145
|
/>
|
|
147
146
|
),
|
|
@@ -151,14 +150,13 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
151
150
|
) : null,
|
|
152
151
|
header: props.localization?.expand,
|
|
153
152
|
id: 'mrt-expand',
|
|
154
|
-
|
|
155
|
-
width: 40,
|
|
153
|
+
size: 50,
|
|
156
154
|
}),
|
|
157
155
|
props.enableRowSelection &&
|
|
158
156
|
createDisplayColumn(table, {
|
|
159
157
|
Cell: ({ cell }) => (
|
|
160
158
|
<MRT_SelectCheckbox
|
|
161
|
-
row={cell.row as
|
|
159
|
+
row={cell.row as any}
|
|
162
160
|
tableInstance={tableInstance}
|
|
163
161
|
/>
|
|
164
162
|
),
|
|
@@ -168,8 +166,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
168
166
|
) : null,
|
|
169
167
|
header: props.localization?.select,
|
|
170
168
|
id: 'mrt-select',
|
|
171
|
-
|
|
172
|
-
width: 40,
|
|
169
|
+
size: 50,
|
|
173
170
|
}),
|
|
174
171
|
props.enableRowNumbers &&
|
|
175
172
|
createDisplayColumn(table, {
|
|
@@ -177,16 +174,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
177
174
|
Header: () => props.localization?.rowNumber,
|
|
178
175
|
header: props.localization?.rowNumbers,
|
|
179
176
|
id: 'mrt-row-numbers',
|
|
180
|
-
|
|
181
|
-
width: 40,
|
|
182
|
-
minWidth: 40,
|
|
177
|
+
size: 50,
|
|
183
178
|
}),
|
|
184
179
|
].filter(Boolean),
|
|
185
180
|
[
|
|
186
181
|
props.editingMode,
|
|
187
182
|
props.enableEditing,
|
|
188
183
|
props.enableExpandAll,
|
|
189
|
-
props.
|
|
184
|
+
props.enableExpanding,
|
|
190
185
|
props.enableGrouping,
|
|
191
186
|
props.enableRowActions,
|
|
192
187
|
props.enableRowNumbers,
|
|
@@ -198,21 +193,21 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
198
193
|
);
|
|
199
194
|
|
|
200
195
|
const columns = useMemo(
|
|
201
|
-
() =>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
column
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
[table, props.columns, currentFilterTypes],
|
|
196
|
+
() => [
|
|
197
|
+
...displayColumns,
|
|
198
|
+
...props.columns.map((column) =>
|
|
199
|
+
column.columns
|
|
200
|
+
? createGroup(table, column as any, currentFilterFns)
|
|
201
|
+
: createDataColumn(table, column as any, currentFilterFns),
|
|
202
|
+
),
|
|
203
|
+
],
|
|
204
|
+
[table, props.columns, currentFilterFns],
|
|
211
205
|
);
|
|
212
206
|
|
|
213
|
-
const data: D[
|
|
207
|
+
const data: D[] = useMemo(
|
|
214
208
|
() =>
|
|
215
|
-
props.isLoading
|
|
209
|
+
(props.state?.isLoading || props.state?.showSkeletons) &&
|
|
210
|
+
!props.data.length
|
|
216
211
|
? [...Array(10).fill(null)].map(() =>
|
|
217
212
|
Object.assign(
|
|
218
213
|
{},
|
|
@@ -224,36 +219,45 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
224
219
|
),
|
|
225
220
|
)
|
|
226
221
|
: props.data,
|
|
227
|
-
[props.data, props.isLoading],
|
|
222
|
+
[props.data, props.state?.isLoading, props.state?.showSkeletons],
|
|
228
223
|
);
|
|
229
224
|
|
|
230
225
|
//@ts-ignore
|
|
231
|
-
const tableInstance
|
|
226
|
+
const tableInstance = {
|
|
227
|
+
//@ts-ignore
|
|
232
228
|
...useTableInstance(table, {
|
|
229
|
+
filterFns: defaultFilterFNs,
|
|
230
|
+
//@ts-ignore
|
|
231
|
+
getCoreRowModel: getCoreRowModel(),
|
|
233
232
|
//@ts-ignore
|
|
234
|
-
filterTypes: defaultFilterFNs,
|
|
235
|
-
getColumnFilteredRowModel: getColumnFilteredRowModelSync(),
|
|
236
|
-
getCoreRowModel: getCoreRowModelSync(),
|
|
237
233
|
getExpandedRowModel: getExpandedRowModel(),
|
|
238
|
-
|
|
239
|
-
|
|
234
|
+
//@ts-ignore
|
|
235
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
236
|
+
//@ts-ignore
|
|
237
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
238
|
+
//@ts-ignore
|
|
239
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
240
|
+
//@ts-ignore
|
|
240
241
|
getPaginationRowModel: getPaginationRowModel(),
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
242
|
+
//@ts-ignore
|
|
243
|
+
getSortedRowModel: getSortedRowModel(),
|
|
244
|
+
//@ts-ignore
|
|
245
|
+
getSubRows: (row) => row?.subRows,
|
|
246
|
+
//@ts-ignore
|
|
247
|
+
globalFilterFn: currentGlobalFilterFn,
|
|
244
248
|
onPaginationChange: (updater: any) =>
|
|
245
249
|
setPagination((old) => functionalUpdate(updater, old)),
|
|
246
250
|
...props,
|
|
251
|
+
//@ts-ignore
|
|
247
252
|
columns,
|
|
248
253
|
data,
|
|
249
254
|
idPrefix,
|
|
250
|
-
//@ts-ignore
|
|
251
255
|
initialState,
|
|
252
256
|
state: {
|
|
253
257
|
currentEditingCell,
|
|
254
258
|
currentEditingRow,
|
|
255
|
-
|
|
256
|
-
|
|
259
|
+
currentFilterFns,
|
|
260
|
+
currentGlobalFilterFn,
|
|
257
261
|
isDensePadding,
|
|
258
262
|
isFullScreen,
|
|
259
263
|
//@ts-ignore
|
|
@@ -263,17 +267,15 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
263
267
|
...props.state,
|
|
264
268
|
},
|
|
265
269
|
}),
|
|
266
|
-
//@ts-ignore
|
|
267
270
|
setCurrentEditingCell,
|
|
268
|
-
//@ts-ignore
|
|
269
271
|
setCurrentEditingRow,
|
|
270
|
-
|
|
271
|
-
|
|
272
|
+
setCurrentFilterFns,
|
|
273
|
+
setCurrentGlobalFilterFn,
|
|
272
274
|
setIsDensePadding,
|
|
273
275
|
setIsFullScreen,
|
|
274
276
|
setShowFilters,
|
|
275
277
|
setShowGlobalFilter,
|
|
276
|
-
};
|
|
278
|
+
} as MRT_TableInstance;
|
|
277
279
|
|
|
278
280
|
useEffect(() => {
|
|
279
281
|
if (typeof window === 'undefined' || !props.enablePersistentState) {
|
|
@@ -304,20 +306,18 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
304
306
|
return (
|
|
305
307
|
<>
|
|
306
308
|
<Dialog
|
|
307
|
-
TransitionComponent={Grow}
|
|
308
309
|
PaperComponent={Box}
|
|
310
|
+
TransitionComponent={Grow}
|
|
309
311
|
disablePortal
|
|
310
312
|
fullScreen
|
|
311
313
|
keepMounted={false}
|
|
312
|
-
onClose={() =>
|
|
313
|
-
open={
|
|
314
|
+
onClose={() => setIsFullScreen(false)}
|
|
315
|
+
open={isFullScreen}
|
|
314
316
|
transitionDuration={400}
|
|
315
317
|
>
|
|
316
318
|
<MRT_TablePaper tableInstance={tableInstance} />
|
|
317
319
|
</Dialog>
|
|
318
|
-
{!
|
|
319
|
-
<MRT_TablePaper tableInstance={tableInstance} />
|
|
320
|
-
)}
|
|
320
|
+
{!isFullScreen && <MRT_TablePaper tableInstance={tableInstance} />}
|
|
321
321
|
</>
|
|
322
322
|
);
|
|
323
323
|
};
|
|
@@ -8,16 +8,19 @@ interface Props {
|
|
|
8
8
|
|
|
9
9
|
export const MRT_LinearProgressBar: FC<Props> = ({ tableInstance }) => {
|
|
10
10
|
const {
|
|
11
|
-
options: { muiLinearProgressProps
|
|
11
|
+
options: { muiLinearProgressProps },
|
|
12
|
+
getState,
|
|
12
13
|
} = tableInstance;
|
|
13
14
|
|
|
15
|
+
const { isLoading, showProgressBars } = getState();
|
|
16
|
+
|
|
14
17
|
const linearProgressProps =
|
|
15
18
|
muiLinearProgressProps instanceof Function
|
|
16
19
|
? muiLinearProgressProps({ tableInstance })
|
|
17
20
|
: muiLinearProgressProps;
|
|
18
21
|
|
|
19
22
|
return (
|
|
20
|
-
<Collapse in={
|
|
23
|
+
<Collapse in={isLoading || showProgressBars} mountOnEnter unmountOnExit>
|
|
21
24
|
<LinearProgress
|
|
22
25
|
aria-label="Loading"
|
|
23
26
|
aria-busy="true"
|
|
@@ -11,7 +11,6 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
|
11
11
|
getPrePaginationRowModel,
|
|
12
12
|
getSelectedRowModel,
|
|
13
13
|
getState,
|
|
14
|
-
toggleColumnGrouping,
|
|
15
14
|
options: {
|
|
16
15
|
localization,
|
|
17
16
|
muiTableToolbarAlertBannerProps,
|
|
@@ -57,7 +56,9 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({ tableInstance }) => {
|
|
|
57
56
|
.getAllColumns()
|
|
58
57
|
.find((column) => column.id === columnId)?.header
|
|
59
58
|
}
|
|
60
|
-
onDelete={() =>
|
|
59
|
+
onDelete={() =>
|
|
60
|
+
tableInstance.getColumn(columnId).toggleGrouping()
|
|
61
|
+
}
|
|
61
62
|
/>
|
|
62
63
|
</Fragment>
|
|
63
64
|
))}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { Box, lighten, Theme, Toolbar } from '@mui/material';
|
|
3
3
|
import { MRT_SearchTextField } from '../inputs/MRT_SearchTextField';
|
|
4
4
|
import { MRT_ToolbarInternalButtons } from './MRT_ToolbarInternalButtons';
|
|
5
5
|
import { MRT_TablePagination } from './MRT_TablePagination';
|
|
@@ -8,13 +8,11 @@ import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
|
8
8
|
import { MRT_TableInstance } from '..';
|
|
9
9
|
|
|
10
10
|
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
11
|
-
backgroundColor: theme.palette.background.default,
|
|
12
|
-
backgroundImage:
|
|
13
|
-
theme.palette.common.white,
|
|
14
|
-
0.05,
|
|
15
|
-
)},${alpha(theme.palette.common.white, 0.05)})`,
|
|
11
|
+
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
12
|
+
backgroundImage: 'none',
|
|
16
13
|
display: 'grid',
|
|
17
14
|
p: '0 !important',
|
|
15
|
+
transition: 'all 0.2s ease-in-out',
|
|
18
16
|
width: '100%',
|
|
19
17
|
zIndex: 1,
|
|
20
18
|
});
|
package/src/utils.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import { MRT_ColumnDef,
|
|
3
|
-
import {
|
|
2
|
+
import { MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
|
+
import { MRT_FILTER_OPTION } from './enums';
|
|
4
4
|
import { defaultFilterFNs } from './filtersFNs';
|
|
5
5
|
|
|
6
6
|
export const getAllLeafColumnDefs = (
|
|
@@ -24,31 +24,31 @@ export const getAllLeafColumnDefs = (
|
|
|
24
24
|
export const createGroup = <D extends Record<string, any> = {}>(
|
|
25
25
|
table: Table<D>,
|
|
26
26
|
column: MRT_ColumnDef<D>,
|
|
27
|
-
|
|
27
|
+
currentFilterFns: { [key: string]: MRT_FilterFn },
|
|
28
28
|
): ColumnDef<D> =>
|
|
29
29
|
table.createGroup({
|
|
30
30
|
...column,
|
|
31
31
|
columns: column?.columns?.map?.((col) =>
|
|
32
32
|
col.columns
|
|
33
|
-
? createGroup<D>(table, col,
|
|
34
|
-
: createDataColumn(table, col,
|
|
33
|
+
? createGroup<D>(table, col, currentFilterFns)
|
|
34
|
+
: createDataColumn(table, col, currentFilterFns),
|
|
35
35
|
),
|
|
36
36
|
} as any);
|
|
37
37
|
|
|
38
38
|
export const createDataColumn = <D extends Record<string, any> = {}>(
|
|
39
39
|
table: Table<D>,
|
|
40
40
|
column: MRT_ColumnDef<D>,
|
|
41
|
-
|
|
41
|
+
currentFilterFns: { [key: string]: MRT_FilterFn },
|
|
42
42
|
): ColumnDef<D> => // @ts-ignore
|
|
43
43
|
table.createDataColumn(column.id, {
|
|
44
44
|
filterFn:
|
|
45
|
-
|
|
46
|
-
?
|
|
47
|
-
: defaultFilterFNs[
|
|
45
|
+
currentFilterFns[column.id] instanceof Function
|
|
46
|
+
? currentFilterFns[column.id]
|
|
47
|
+
: defaultFilterFNs[currentFilterFns[column.id] as MRT_FILTER_OPTION],
|
|
48
48
|
...column,
|
|
49
49
|
}) as any;
|
|
50
50
|
|
|
51
51
|
export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
52
52
|
table: Table<D>,
|
|
53
53
|
column: Omit<MRT_ColumnDef<D>, 'header'> & { header?: string },
|
|
54
|
-
): ColumnDef<D> => table.createDisplayColumn(column);
|
|
54
|
+
): ColumnDef<D> => table.createDisplayColumn(column as ColumnDef<D>);
|