material-react-table 0.7.4 → 0.7.5
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 +17 -21
- package/dist/enums.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +84 -80
- 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 +84 -80
- 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/utils.d.ts +6 -6
- package/package.json +2 -2
- package/src/MaterialReactTable.tsx +26 -21
- package/src/enums.ts +1 -1
- package/src/head/MRT_TableHeadCell.tsx +3 -5
- package/src/inputs/MRT_FilterTextField.tsx +16 -16
- package/src/inputs/MRT_SearchTextField.tsx +2 -2
- package/src/menus/MRT_ColumnActionMenu.tsx +2 -2
- package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +35 -33
- package/src/table/MRT_TableRoot.tsx +26 -26
- package/src/utils.ts +10 -10
|
@@ -13,11 +13,12 @@ import {
|
|
|
13
13
|
useTableInstance,
|
|
14
14
|
getCoreRowModelSync,
|
|
15
15
|
ColumnDef,
|
|
16
|
+
FilterFn,
|
|
16
17
|
} from '@tanstack/react-table';
|
|
17
18
|
import {
|
|
18
19
|
MRT_Cell,
|
|
19
20
|
MRT_ColumnDef,
|
|
20
|
-
|
|
21
|
+
MRT_FilterFn,
|
|
21
22
|
MRT_Row,
|
|
22
23
|
MRT_TableInstance,
|
|
23
24
|
MRT_TableState,
|
|
@@ -35,7 +36,7 @@ import {
|
|
|
35
36
|
getAllLeafColumnDefs,
|
|
36
37
|
} from '../utils';
|
|
37
38
|
import { defaultFilterFNs } from '../filtersFNs';
|
|
38
|
-
import {
|
|
39
|
+
import { MRT_FILTER_OPTION } from '../enums';
|
|
39
40
|
import { Box, Dialog, Grow } from '@mui/material';
|
|
40
41
|
|
|
41
42
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
@@ -98,25 +99,25 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
98
99
|
pageCount: initialState?.pagination?.pageCount ?? -1,
|
|
99
100
|
});
|
|
100
101
|
|
|
101
|
-
const [
|
|
102
|
-
[key: string]:
|
|
102
|
+
const [currentFilterFns, setCurrentFilterFns] = useState<{
|
|
103
|
+
[key: string]: MRT_FilterFn;
|
|
103
104
|
}>(() =>
|
|
104
105
|
Object.assign(
|
|
105
106
|
{},
|
|
106
107
|
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map((c) => ({
|
|
107
108
|
[c.id as string]:
|
|
108
|
-
c.
|
|
109
|
-
initialState?.
|
|
109
|
+
c.filterFn ??
|
|
110
|
+
initialState?.currentFilterFns?.[c.id] ??
|
|
110
111
|
(!!c.filterSelectOptions?.length
|
|
111
|
-
?
|
|
112
|
-
:
|
|
112
|
+
? MRT_FILTER_OPTION.EQUALS
|
|
113
|
+
: MRT_FILTER_OPTION.BEST_MATCH),
|
|
113
114
|
})),
|
|
114
115
|
),
|
|
115
116
|
);
|
|
116
117
|
|
|
117
|
-
const [
|
|
118
|
-
|
|
119
|
-
);
|
|
118
|
+
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] = useState<
|
|
119
|
+
MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol
|
|
120
|
+
>(props.globalFilterFn ?? MRT_FILTER_OPTION.BEST_MATCH_FIRST);
|
|
120
121
|
|
|
121
122
|
const table = useMemo(() => createTable() as unknown as Table<D>, []);
|
|
122
123
|
|
|
@@ -203,11 +204,11 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
203
204
|
...displayColumns,
|
|
204
205
|
...props.columns.map((column) =>
|
|
205
206
|
column.columns
|
|
206
|
-
? createGroup(table, column,
|
|
207
|
-
: createDataColumn(table, column,
|
|
207
|
+
? createGroup(table, column, currentFilterFns)
|
|
208
|
+
: createDataColumn(table, column, currentFilterFns),
|
|
208
209
|
),
|
|
209
210
|
] as ColumnDef<D>[]),
|
|
210
|
-
[table, props.columns,
|
|
211
|
+
[table, props.columns, currentFilterFns],
|
|
211
212
|
);
|
|
212
213
|
|
|
213
214
|
const data: D['Row'][] = useMemo(
|
|
@@ -231,7 +232,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
231
232
|
const tableInstance: MRT_TableInstance<{}> = {
|
|
232
233
|
...useTableInstance(table, {
|
|
233
234
|
//@ts-ignore
|
|
234
|
-
|
|
235
|
+
filterFns: defaultFilterFNs,
|
|
235
236
|
getColumnFilteredRowModel: getColumnFilteredRowModelSync(),
|
|
236
237
|
getCoreRowModel: getCoreRowModelSync(),
|
|
237
238
|
getExpandedRowModel: getExpandedRowModel(),
|
|
@@ -240,7 +241,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
240
241
|
getPaginationRowModel: getPaginationRowModel(),
|
|
241
242
|
getSortedRowModel: getSortedRowModelSync(),
|
|
242
243
|
getSubRows: (originalRow: D) => originalRow.subRows,
|
|
243
|
-
|
|
244
|
+
globalFilterFn: currentGlobalFilterFn,
|
|
244
245
|
onPaginationChange: (updater: any) =>
|
|
245
246
|
setPagination((old) => functionalUpdate(updater, old)),
|
|
246
247
|
...props,
|
|
@@ -252,8 +253,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
252
253
|
state: {
|
|
253
254
|
currentEditingCell,
|
|
254
255
|
currentEditingRow,
|
|
255
|
-
|
|
256
|
-
|
|
256
|
+
currentFilterFns,
|
|
257
|
+
currentGlobalFilterFn,
|
|
257
258
|
isDensePadding,
|
|
258
259
|
isFullScreen,
|
|
259
260
|
//@ts-ignore
|
|
@@ -267,8 +268,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
267
268
|
setCurrentEditingCell,
|
|
268
269
|
//@ts-ignore
|
|
269
270
|
setCurrentEditingRow,
|
|
270
|
-
|
|
271
|
-
|
|
271
|
+
setCurrentFilterFns,
|
|
272
|
+
//@ts-ignore
|
|
273
|
+
setCurrentGlobalFilterFn,
|
|
272
274
|
setIsDensePadding,
|
|
273
275
|
setIsFullScreen,
|
|
274
276
|
setShowFilters,
|
|
@@ -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
|
};
|
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>);
|