material-react-table 0.14.5 → 0.15.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 +14 -7
- package/dist/{filtersFNs.d.ts → filtersFns.d.ts} +1 -1
- package/dist/inputs/{MRT_SearchTextField.d.ts → MRT_GlobalFilterTextField.d.ts} +1 -1
- package/dist/material-react-table.cjs.development.js +100 -38
- 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 +102 -40
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/sortingFns.d.ts +5 -0
- package/dist/utils.d.ts +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +27 -11
- package/src/body/MRT_TableBody.tsx +34 -6
- package/src/buttons/MRT_ExpandAllButton.tsx +25 -19
- package/src/buttons/MRT_ExpandButton.tsx +25 -23
- package/src/{filtersFNs.ts → filtersFns.ts} +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +12 -4
- package/src/inputs/{MRT_SearchTextField.tsx → MRT_GlobalFilterTextField.tsx} +18 -12
- package/src/menus/MRT_FilterOptionMenu.tsx +1 -1
- package/src/sortingFns.ts +25 -0
- package/src/table/MRT_TableRoot.tsx +17 -14
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +2 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +3 -3
- package/src/utils.ts +2 -2
package/dist/utils.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ 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>, currentFilterFns: {
|
|
8
8
|
[key: string]: import("@tanstack/react-table").FilterFnOption<import("@tanstack/react-table").TableGenerics>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enableColumnFilterChangeMode" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
|
13
13
|
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.15.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -38,6 +38,8 @@ import {
|
|
|
38
38
|
Overwrite,
|
|
39
39
|
ReactTableGenerics,
|
|
40
40
|
Row,
|
|
41
|
+
SortingFn,
|
|
42
|
+
SortingFnOption,
|
|
41
43
|
TableGenerics,
|
|
42
44
|
TableInstance,
|
|
43
45
|
TableState,
|
|
@@ -52,13 +54,12 @@ import { MRT_TableRoot } from './table/MRT_TableRoot';
|
|
|
52
54
|
export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
|
|
53
55
|
Omit<
|
|
54
56
|
UseTableInstanceOptions<ReactTableGenerics>,
|
|
55
|
-
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
|
57
|
+
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
|
56
58
|
>
|
|
57
59
|
> & {
|
|
58
60
|
columns: MRT_ColumnDef<D>[];
|
|
59
61
|
data: D[];
|
|
60
62
|
expandRowsFn?: (dataRow: D) => D[];
|
|
61
|
-
filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
|
|
62
63
|
initialState?: Partial<MRT_TableState<D>>;
|
|
63
64
|
state?: Partial<MRT_TableState<D>>;
|
|
64
65
|
};
|
|
@@ -87,6 +88,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
87
88
|
| 'getFlatHeaders'
|
|
88
89
|
| 'getLeftLeafColumns'
|
|
89
90
|
| 'getPaginationRowModel'
|
|
91
|
+
| 'getPreFilteredRowModel'
|
|
90
92
|
| 'getPrePaginationRowModel'
|
|
91
93
|
| 'getRightLeafColumns'
|
|
92
94
|
| 'getRowModel'
|
|
@@ -103,6 +105,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
103
105
|
getFlatHeaders: () => MRT_Header<D>[];
|
|
104
106
|
getLeftLeafColumns: () => MRT_Column<D>[];
|
|
105
107
|
getPaginationRowModel: () => MRT_RowModel<D>;
|
|
108
|
+
getPreFilteredRowModel: () => MRT_RowModel<D>;
|
|
106
109
|
getPrePaginationRowModel: () => MRT_RowModel<D>;
|
|
107
110
|
getRightLeafColumns: () => MRT_Column<D>[];
|
|
108
111
|
getRowModel: () => MRT_RowModel<D>;
|
|
@@ -145,11 +148,12 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
145
148
|
ColumnDef<D>,
|
|
146
149
|
| 'accessorFn'
|
|
147
150
|
| 'aggregatedCell'
|
|
148
|
-
| '
|
|
149
|
-
| 'footer'
|
|
151
|
+
| 'cell'
|
|
150
152
|
| 'columns'
|
|
151
153
|
| 'filterFn'
|
|
152
|
-
| '
|
|
154
|
+
| 'footer'
|
|
155
|
+
| 'header'
|
|
156
|
+
| 'sortingFn'
|
|
153
157
|
> & {
|
|
154
158
|
AggregatedCell?: ({
|
|
155
159
|
cell,
|
|
@@ -203,6 +207,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
203
207
|
enableColumnActions?: boolean;
|
|
204
208
|
enableColumnOrdering?: boolean;
|
|
205
209
|
enableEditing?: boolean;
|
|
210
|
+
enableColumnFilterChangeMode?: boolean;
|
|
206
211
|
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[] | null;
|
|
207
212
|
filterFn?: MRT_FilterFn;
|
|
208
213
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
@@ -312,6 +317,7 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
312
317
|
filterValue: any;
|
|
313
318
|
instance: MRT_TableInstance<D>;
|
|
314
319
|
}) => void;
|
|
320
|
+
sortingFn?: MRT_SortingFn;
|
|
315
321
|
};
|
|
316
322
|
|
|
317
323
|
export type MRT_Column<D extends Record<string, any> = {}> = Omit<
|
|
@@ -357,6 +363,10 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
|
|
|
357
363
|
row: MRT_Row<D>;
|
|
358
364
|
};
|
|
359
365
|
|
|
366
|
+
export type MRT_SortingOption = SortingFnOption<TableGenerics> | 'fuzzy';
|
|
367
|
+
|
|
368
|
+
export type MRT_SortingFn = SortingFn<TableGenerics> | MRT_SortingOption;
|
|
369
|
+
|
|
360
370
|
export type MRT_FILTER_OPTION =
|
|
361
371
|
| 'between'
|
|
362
372
|
| 'contains'
|
|
@@ -373,23 +383,21 @@ export type MRT_FILTER_OPTION =
|
|
|
373
383
|
| 'startsWith'
|
|
374
384
|
| FilterFnOption<TableGenerics>;
|
|
375
385
|
|
|
376
|
-
export type MRT_FilterFn =
|
|
377
|
-
| FilterFn<TableGenerics>
|
|
378
|
-
| MRT_FILTER_OPTION
|
|
379
|
-
| number
|
|
380
|
-
| string
|
|
381
|
-
| symbol;
|
|
386
|
+
export type MRT_FilterFn = FilterFn<TableGenerics> | MRT_FILTER_OPTION;
|
|
382
387
|
|
|
383
388
|
export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
384
389
|
MRT_TableOptions<D> & {
|
|
385
390
|
editingMode?: 'table' | 'row' | 'cell';
|
|
386
391
|
enableClickToCopy?: boolean;
|
|
387
392
|
enableColumnActions?: boolean;
|
|
393
|
+
enableColumnFilterChangeMode?: boolean;
|
|
388
394
|
enableColumnOrdering?: boolean;
|
|
389
395
|
enableDensityToggle?: boolean;
|
|
390
396
|
enableEditing?: boolean;
|
|
391
397
|
enableExpandAll?: boolean;
|
|
392
398
|
enableFullScreenToggle?: boolean;
|
|
399
|
+
enableGlobalFilterChangeMode?: boolean;
|
|
400
|
+
enableGlobalFilterRankedResults?: boolean;
|
|
393
401
|
enablePagination?: boolean;
|
|
394
402
|
enablePersistentState?: boolean;
|
|
395
403
|
enableRowActions?: boolean;
|
|
@@ -833,6 +841,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
833
841
|
defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
|
|
834
842
|
editingMode = 'row',
|
|
835
843
|
enableColumnActions = true,
|
|
844
|
+
enableColumnFilterChangeMode = true,
|
|
836
845
|
enableColumnFilters = true,
|
|
837
846
|
enableColumnOrdering = false,
|
|
838
847
|
enableColumnResizing = false,
|
|
@@ -841,9 +850,12 @@ export default <D extends Record<string, any> = {}>({
|
|
|
841
850
|
enableFilters = true,
|
|
842
851
|
enableFullScreenToggle = true,
|
|
843
852
|
enableGlobalFilter = true,
|
|
853
|
+
enableGlobalFilterChangeMode = true,
|
|
854
|
+
enableGlobalFilterRankedResults = true,
|
|
844
855
|
enableGrouping = false,
|
|
845
856
|
enableHiding = true,
|
|
846
857
|
enableMultiRowSelection = true,
|
|
858
|
+
enableMultiSort = true,
|
|
847
859
|
enablePagination = true,
|
|
848
860
|
enablePinning = false,
|
|
849
861
|
enableRowSelection = false,
|
|
@@ -872,6 +884,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
872
884
|
defaultColumn={defaultColumn}
|
|
873
885
|
editingMode={editingMode}
|
|
874
886
|
enableColumnActions={enableColumnActions}
|
|
887
|
+
enableColumnFilterChangeMode={enableColumnFilterChangeMode}
|
|
875
888
|
enableColumnFilters={enableColumnFilters}
|
|
876
889
|
enableColumnOrdering={enableColumnOrdering}
|
|
877
890
|
enableColumnResizing={enableColumnResizing}
|
|
@@ -880,9 +893,12 @@ export default <D extends Record<string, any> = {}>({
|
|
|
880
893
|
enableFilters={enableFilters}
|
|
881
894
|
enableFullScreenToggle={enableFullScreenToggle}
|
|
882
895
|
enableGlobalFilter={enableGlobalFilter}
|
|
896
|
+
enableGlobalFilterChangeMode={enableGlobalFilterChangeMode}
|
|
897
|
+
enableGlobalFilterRankedResults={enableGlobalFilterRankedResults}
|
|
883
898
|
enableGrouping={enableGrouping}
|
|
884
899
|
enableHiding={enableHiding}
|
|
885
900
|
enableMultiRowSelection={enableMultiRowSelection}
|
|
901
|
+
enableMultiSort={enableMultiSort}
|
|
886
902
|
enablePagination={enablePagination}
|
|
887
903
|
enablePinning={enablePinning}
|
|
888
904
|
enableRowSelection={enableRowSelection}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import React, { FC, RefObject } from 'react';
|
|
1
|
+
import React, { FC, RefObject, useMemo } from 'react';
|
|
2
2
|
import { useVirtual } from 'react-virtual';
|
|
3
3
|
import { TableBody } from '@mui/material';
|
|
4
4
|
import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
5
5
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
6
|
+
import { rankGlobalFuzzy } from '../sortingFns';
|
|
6
7
|
|
|
7
8
|
interface Props {
|
|
8
9
|
instance: MRT_TableInstance;
|
|
@@ -15,6 +16,7 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
|
15
16
|
getPrePaginationRowModel,
|
|
16
17
|
getState,
|
|
17
18
|
options: {
|
|
19
|
+
enableGlobalFilterRankedResults,
|
|
18
20
|
enablePagination,
|
|
19
21
|
enableRowVirtualization,
|
|
20
22
|
muiTableBodyProps,
|
|
@@ -22,20 +24,46 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
|
22
24
|
},
|
|
23
25
|
} = instance;
|
|
24
26
|
|
|
25
|
-
const { density } = getState();
|
|
27
|
+
const { density, globalFilter, pagination, sorting } = getState();
|
|
26
28
|
|
|
27
29
|
const tableBodyProps =
|
|
28
30
|
muiTableBodyProps instanceof Function
|
|
29
31
|
? muiTableBodyProps({ instance })
|
|
30
32
|
: muiTableBodyProps;
|
|
31
33
|
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
34
|
+
const getIsSomeColumnsSorted = () => {
|
|
35
|
+
return Object.values(sorting).some(Boolean);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const rows = useMemo(() => {
|
|
39
|
+
if (
|
|
40
|
+
enableGlobalFilterRankedResults &&
|
|
41
|
+
globalFilter &&
|
|
42
|
+
!getIsSomeColumnsSorted()
|
|
43
|
+
) {
|
|
44
|
+
const rankedRows = getPrePaginationRowModel().rows.sort((a, b) =>
|
|
45
|
+
rankGlobalFuzzy(a, b),
|
|
46
|
+
);
|
|
47
|
+
if (enablePagination) {
|
|
48
|
+
return rankedRows.slice(0, pagination.pageSize);
|
|
49
|
+
}
|
|
50
|
+
return rankedRows;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return enablePagination
|
|
54
|
+
? getPaginationRowModel().rows
|
|
55
|
+
: getPrePaginationRowModel().rows;
|
|
56
|
+
}, [
|
|
57
|
+
enableGlobalFilterRankedResults,
|
|
58
|
+
(enableGlobalFilterRankedResults && globalFilter) || !enablePagination
|
|
59
|
+
? getPrePaginationRowModel().rows
|
|
60
|
+
: getPaginationRowModel().rows,
|
|
61
|
+
globalFilter,
|
|
62
|
+
]);
|
|
35
63
|
|
|
36
64
|
const rowVirtualizer = enableRowVirtualization
|
|
37
65
|
? useVirtual({
|
|
38
|
-
overscan: density === 'compact' ?
|
|
66
|
+
overscan: density === 'compact' ? 20 : 10,
|
|
39
67
|
size: rows.length,
|
|
40
68
|
parentRef: tableContainerRef,
|
|
41
69
|
...virtualizerProps,
|
|
@@ -35,26 +35,32 @@ export const MRT_ExpandAllButton: FC<Props> = ({ instance }) => {
|
|
|
35
35
|
enterNextDelay={1000}
|
|
36
36
|
title={localization.expandAll}
|
|
37
37
|
>
|
|
38
|
-
<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
>
|
|
49
|
-
<KeyboardDoubleArrowDownIcon
|
|
50
|
-
style={{
|
|
51
|
-
transform: `rotate(${
|
|
52
|
-
getIsAllRowsExpanded() ? -180 : getIsSomeRowsExpanded() ? -90 : 0
|
|
53
|
-
}deg)`,
|
|
54
|
-
transition: 'transform 0.2s',
|
|
38
|
+
<span>
|
|
39
|
+
<IconButton
|
|
40
|
+
aria-label={localization.expandAll}
|
|
41
|
+
disabled={!getCanSomeRowsExpand() && !renderDetailPanel}
|
|
42
|
+
onClick={() => toggleAllRowsExpanded(!getIsAllRowsExpanded())}
|
|
43
|
+
{...iconButtonProps}
|
|
44
|
+
sx={{
|
|
45
|
+
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
46
|
+
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
47
|
+
...iconButtonProps?.sx,
|
|
55
48
|
}}
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
>
|
|
50
|
+
<KeyboardDoubleArrowDownIcon
|
|
51
|
+
style={{
|
|
52
|
+
transform: `rotate(${
|
|
53
|
+
getIsAllRowsExpanded()
|
|
54
|
+
? -180
|
|
55
|
+
: getIsSomeRowsExpanded()
|
|
56
|
+
? -90
|
|
57
|
+
: 0
|
|
58
|
+
}deg)`,
|
|
59
|
+
transition: 'transform 0.2s',
|
|
60
|
+
}}
|
|
61
|
+
/>
|
|
62
|
+
</IconButton>
|
|
63
|
+
</span>
|
|
58
64
|
</Tooltip>
|
|
59
65
|
);
|
|
60
66
|
};
|
|
@@ -38,30 +38,32 @@ export const MRT_ExpandButton: FC<Props> = ({ row, instance }) => {
|
|
|
38
38
|
enterNextDelay={1000}
|
|
39
39
|
title={localization.expand}
|
|
40
40
|
>
|
|
41
|
-
<
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
>
|
|
52
|
-
<ExpandMoreIcon
|
|
53
|
-
style={{
|
|
54
|
-
transform: `rotate(${
|
|
55
|
-
!row.getCanExpand() && !renderDetailPanel
|
|
56
|
-
? -90
|
|
57
|
-
: row.getIsExpanded()
|
|
58
|
-
? -180
|
|
59
|
-
: 0
|
|
60
|
-
}deg)`,
|
|
61
|
-
transition: 'transform 0.2s',
|
|
41
|
+
<span>
|
|
42
|
+
<IconButton
|
|
43
|
+
aria-label={localization.expand}
|
|
44
|
+
disabled={!row.getCanExpand() && !renderDetailPanel}
|
|
45
|
+
onClick={handleToggleExpand}
|
|
46
|
+
{...iconButtonProps}
|
|
47
|
+
sx={{
|
|
48
|
+
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
49
|
+
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
|
50
|
+
...iconButtonProps?.sx,
|
|
62
51
|
}}
|
|
63
|
-
|
|
64
|
-
|
|
52
|
+
>
|
|
53
|
+
<ExpandMoreIcon
|
|
54
|
+
style={{
|
|
55
|
+
transform: `rotate(${
|
|
56
|
+
!row.getCanExpand() && !renderDetailPanel
|
|
57
|
+
? -90
|
|
58
|
+
: row.getIsExpanded()
|
|
59
|
+
? -180
|
|
60
|
+
: 0
|
|
61
|
+
}deg)`,
|
|
62
|
+
transition: 'transform 0.2s',
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
</IconButton>
|
|
66
|
+
</span>
|
|
65
67
|
</Tooltip>
|
|
66
68
|
);
|
|
67
69
|
};
|
|
@@ -32,6 +32,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
32
32
|
const {
|
|
33
33
|
getState,
|
|
34
34
|
options: {
|
|
35
|
+
enableColumnFilterChangeMode,
|
|
35
36
|
enabledColumnFilterOptions,
|
|
36
37
|
icons: { FilterListIcon, CloseIcon },
|
|
37
38
|
localization,
|
|
@@ -176,6 +177,10 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
176
177
|
const allowedColumnFilterOptions =
|
|
177
178
|
columnDef?.enabledColumnFilterOptions ?? enabledColumnFilterOptions;
|
|
178
179
|
|
|
180
|
+
const allowColumnChangeMode =
|
|
181
|
+
enableColumnFilterChangeMode &&
|
|
182
|
+
columnDef.enableColumnFilterChangeMode !== false;
|
|
183
|
+
|
|
179
184
|
return (
|
|
180
185
|
<>
|
|
181
186
|
<TextField
|
|
@@ -190,6 +195,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
190
195
|
title: filterPlaceholder,
|
|
191
196
|
}}
|
|
192
197
|
helperText={
|
|
198
|
+
allowColumnChangeMode &&
|
|
193
199
|
!inputIndex &&
|
|
194
200
|
(allowedColumnFilterOptions === undefined ||
|
|
195
201
|
(allowedColumnFilterOptions?.length ?? 0) > 0) ? (
|
|
@@ -224,7 +230,6 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
224
230
|
whiteSpace: 'nowrap',
|
|
225
231
|
},
|
|
226
232
|
}}
|
|
227
|
-
label={isSelectFilter && !filterValue ? filterPlaceholder : undefined}
|
|
228
233
|
margin="none"
|
|
229
234
|
placeholder={
|
|
230
235
|
filterChipLabel || isSelectFilter ? undefined : filterPlaceholder
|
|
@@ -235,10 +240,12 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
235
240
|
value={filterValue ?? ''}
|
|
236
241
|
variant="standard"
|
|
237
242
|
InputProps={{
|
|
238
|
-
startAdornment:
|
|
243
|
+
startAdornment:
|
|
244
|
+
allowColumnChangeMode &&
|
|
245
|
+
!isSelectFilter &&
|
|
239
246
|
!inputIndex &&
|
|
240
247
|
(allowedColumnFilterOptions === undefined ||
|
|
241
|
-
|
|
248
|
+
!!allowedColumnFilterOptions?.length) ? (
|
|
242
249
|
<InputAdornment position="start">
|
|
243
250
|
<Tooltip arrow title={localization.changeFilterMode}>
|
|
244
251
|
<span>
|
|
@@ -259,6 +266,8 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
259
266
|
/>
|
|
260
267
|
)}
|
|
261
268
|
</InputAdornment>
|
|
269
|
+
) : (
|
|
270
|
+
<FilterListIcon />
|
|
262
271
|
),
|
|
263
272
|
endAdornment: !filterChipLabel && (
|
|
264
273
|
<InputAdornment position="end">
|
|
@@ -292,7 +301,6 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
|
292
301
|
p: 0,
|
|
293
302
|
minWidth: !filterChipLabel ? '8rem' : 'auto',
|
|
294
303
|
width: 'calc(100% + 0.5rem)',
|
|
295
|
-
mt: isSelectFilter && !filterValue ? '-1rem' : undefined,
|
|
296
304
|
'& .MuiSelect-icon': {
|
|
297
305
|
mr: '1.5rem',
|
|
298
306
|
},
|
|
@@ -20,17 +20,18 @@ interface Props {
|
|
|
20
20
|
instance: MRT_TableInstance;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
export const
|
|
23
|
+
export const MRT_GlobalFilterTextField: FC<Props> = ({ instance }) => {
|
|
24
24
|
const {
|
|
25
25
|
getState,
|
|
26
26
|
setGlobalFilter,
|
|
27
27
|
options: {
|
|
28
|
+
enableGlobalFilterChangeMode,
|
|
28
29
|
icons: { SearchIcon, CloseIcon },
|
|
29
|
-
tableId,
|
|
30
30
|
localization,
|
|
31
31
|
muiSearchTextFieldProps,
|
|
32
32
|
onGlobalFilterValueChanged,
|
|
33
33
|
onGlobalFilterValueChangedDebounced,
|
|
34
|
+
tableId,
|
|
34
35
|
},
|
|
35
36
|
} = instance;
|
|
36
37
|
|
|
@@ -76,7 +77,7 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
76
77
|
value={searchValue ?? ''}
|
|
77
78
|
variant="standard"
|
|
78
79
|
InputProps={{
|
|
79
|
-
startAdornment: (
|
|
80
|
+
startAdornment: enableGlobalFilterChangeMode ? (
|
|
80
81
|
<InputAdornment position="start">
|
|
81
82
|
<Tooltip arrow title={localization.changeSearchMode}>
|
|
82
83
|
<IconButton
|
|
@@ -89,18 +90,23 @@ export const MRT_SearchTextField: FC<Props> = ({ instance }) => {
|
|
|
89
90
|
</IconButton>
|
|
90
91
|
</Tooltip>
|
|
91
92
|
</InputAdornment>
|
|
93
|
+
) : (
|
|
94
|
+
<SearchIcon />
|
|
92
95
|
),
|
|
93
96
|
endAdornment: (
|
|
94
97
|
<InputAdornment position="end">
|
|
95
|
-
<
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
98
|
+
<Tooltip arrow title={localization.clearSearch ?? ''}>
|
|
99
|
+
<span>
|
|
100
|
+
<IconButton
|
|
101
|
+
aria-label={localization.clearSearch}
|
|
102
|
+
disabled={!searchValue?.length}
|
|
103
|
+
onClick={handleClear}
|
|
104
|
+
size="small"
|
|
105
|
+
>
|
|
106
|
+
<CloseIcon />
|
|
107
|
+
</IconButton>
|
|
108
|
+
</span>
|
|
109
|
+
</Tooltip>
|
|
104
110
|
</InputAdornment>
|
|
105
111
|
),
|
|
106
112
|
}}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
|
+
import { Row, sortingFns } from '@tanstack/react-table';
|
|
3
|
+
import type { MRT_Row } from '.';
|
|
4
|
+
|
|
5
|
+
const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
|
|
6
|
+
let dir = 0;
|
|
7
|
+
if (rowA.columnFiltersMeta[columnId]) {
|
|
8
|
+
dir = compareItems(
|
|
9
|
+
rowA.columnFiltersMeta[columnId]! as RankingInfo,
|
|
10
|
+
rowB.columnFiltersMeta[columnId]! as RankingInfo,
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
// Provide a fallback for when the item ranks are equal
|
|
14
|
+
return dir === 0
|
|
15
|
+
? sortingFns.alphanumeric(rowA as Row<any>, rowB as Row<any>, columnId)
|
|
16
|
+
: dir;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const MRT_SortingFns = {
|
|
20
|
+
fuzzy,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const rankGlobalFuzzy = (rowA: MRT_Row, rowB: MRT_Row) =>
|
|
24
|
+
Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
|
|
25
|
+
Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
|
|
@@ -1,18 +1,20 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
FilterFn,
|
|
4
|
+
ReactTableGenerics,
|
|
5
|
+
Table,
|
|
6
|
+
TableState,
|
|
4
7
|
createTable,
|
|
8
|
+
filterFns,
|
|
9
|
+
getCoreRowModel,
|
|
5
10
|
getExpandedRowModel,
|
|
6
|
-
|
|
7
|
-
|
|
11
|
+
getFacetedRowModel,
|
|
12
|
+
getFilteredRowModel,
|
|
8
13
|
getGroupedRowModel,
|
|
14
|
+
getPaginationRowModel,
|
|
9
15
|
getSortedRowModel,
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
ReactTableGenerics,
|
|
13
|
-
getFacetedRowModel,
|
|
14
|
-
TableState,
|
|
15
|
-
Table,
|
|
16
|
+
useTableInstance,
|
|
17
|
+
sortingFns,
|
|
16
18
|
} from '@tanstack/react-table';
|
|
17
19
|
import {
|
|
18
20
|
MRT_Cell,
|
|
@@ -29,6 +31,7 @@ import { MRT_ToggleRowActionMenuButton } from '../buttons/MRT_ToggleRowActionMen
|
|
|
29
31
|
import { MRT_SelectCheckbox } from '../inputs/MRT_SelectCheckbox';
|
|
30
32
|
import { MaterialReactTableProps } from '../MaterialReactTable';
|
|
31
33
|
import { MRT_TablePaper } from './MRT_TablePaper';
|
|
34
|
+
import { Box, Dialog, Grow } from '@mui/material';
|
|
32
35
|
import {
|
|
33
36
|
createDataColumn,
|
|
34
37
|
createDisplayColumn,
|
|
@@ -36,8 +39,8 @@ import {
|
|
|
36
39
|
getAllLeafColumnDefs,
|
|
37
40
|
getDefaultColumnOrderIds,
|
|
38
41
|
} from '../utils';
|
|
39
|
-
import {
|
|
40
|
-
import {
|
|
42
|
+
import { MRT_FilterFns } from '../filtersFns';
|
|
43
|
+
import { MRT_SortingFns } from '../sortingFns';
|
|
41
44
|
|
|
42
45
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
43
46
|
props: MaterialReactTableProps<D>,
|
|
@@ -123,8 +126,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
123
126
|
() =>
|
|
124
127
|
// @ts-ignore
|
|
125
128
|
createTable().setOptions({
|
|
126
|
-
|
|
127
|
-
filterFns: defaultFilterFNs,
|
|
129
|
+
filterFns: { ...filterFns, ...MRT_FilterFns, ...props.filterFns },
|
|
128
130
|
getCoreRowModel: getCoreRowModel(),
|
|
129
131
|
getExpandedRowModel: getExpandedRowModel(),
|
|
130
132
|
getFacetedRowModel: getFacetedRowModel(),
|
|
@@ -132,8 +134,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
132
134
|
getGroupedRowModel: getGroupedRowModel(),
|
|
133
135
|
getPaginationRowModel: getPaginationRowModel(),
|
|
134
136
|
getSortedRowModel: getSortedRowModel(),
|
|
135
|
-
|
|
136
|
-
tableId,
|
|
137
|
+
sortingFns: { ...sortingFns, ...MRT_SortingFns, ...props.sortingFns },
|
|
137
138
|
}) as Table<D>,
|
|
138
139
|
[],
|
|
139
140
|
);
|
|
@@ -252,6 +253,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
252
253
|
//@ts-ignore
|
|
253
254
|
columns,
|
|
254
255
|
data,
|
|
256
|
+
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
255
257
|
//@ts-ignore
|
|
256
258
|
globalFilterFn: currentGlobalFilterFn,
|
|
257
259
|
initialState,
|
|
@@ -267,6 +269,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
267
269
|
showGlobalFilter,
|
|
268
270
|
...props.state,
|
|
269
271
|
} as TableState,
|
|
272
|
+
tableId,
|
|
270
273
|
}),
|
|
271
274
|
setCurrentEditingCell:
|
|
272
275
|
props.onCurrentEditingCellChange ?? setCurrentEditingCell,
|
|
@@ -6,7 +6,7 @@ import { MRT_ToggleDensePaddingButton } from '../buttons/MRT_ToggleDensePaddingB
|
|
|
6
6
|
import { MRT_ToggleFiltersButton } from '../buttons/MRT_ToggleFiltersButton';
|
|
7
7
|
import { MRT_ToggleGlobalFilterButton } from '../buttons/MRT_ToggleGlobalFilterButton';
|
|
8
8
|
import { MRT_TableInstance } from '..';
|
|
9
|
-
import {
|
|
9
|
+
import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
12
|
instance: MRT_TableInstance;
|
|
@@ -44,7 +44,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
|
|
|
44
44
|
}) ?? (
|
|
45
45
|
<>
|
|
46
46
|
{enableGlobalFilter && positionGlobalFilter === 'right' && (
|
|
47
|
-
<
|
|
47
|
+
<MRT_GlobalFilterTextField instance={instance} />
|
|
48
48
|
)}
|
|
49
49
|
{enableFilters && enableGlobalFilter && (
|
|
50
50
|
<MRT_ToggleGlobalFilterButton instance={instance} />
|
|
@@ -5,7 +5,7 @@ import { MRT_TablePagination } from './MRT_TablePagination';
|
|
|
5
5
|
import { MRT_ToolbarAlertBanner } from './MRT_ToolbarAlertBanner';
|
|
6
6
|
import { MRT_LinearProgressBar } from './MRT_LinearProgressBar';
|
|
7
7
|
import { MRT_TableInstance } from '..';
|
|
8
|
-
import {
|
|
8
|
+
import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
|
|
9
9
|
|
|
10
10
|
export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
11
11
|
backgroundColor: lighten(theme.palette.background.default, 0.04),
|
|
@@ -86,7 +86,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
86
86
|
}}
|
|
87
87
|
>
|
|
88
88
|
{enableGlobalFilter && positionGlobalFilter === 'left' && (
|
|
89
|
-
<
|
|
89
|
+
<MRT_GlobalFilterTextField instance={instance} />
|
|
90
90
|
)}
|
|
91
91
|
|
|
92
92
|
{renderToolbarTopCustomActions?.({ instance }) ?? <span />}
|
|
@@ -95,7 +95,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
95
95
|
) : (
|
|
96
96
|
enableGlobalFilter &&
|
|
97
97
|
positionGlobalFilter === 'right' && (
|
|
98
|
-
<
|
|
98
|
+
<MRT_GlobalFilterTextField instance={instance} />
|
|
99
99
|
)
|
|
100
100
|
)}
|
|
101
101
|
</Box>
|