material-react-table 0.24.1 → 0.26.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/README.md +13 -11
- package/dist/MaterialReactTable.d.ts +18 -16
- package/dist/{utils.d.ts → column.utils.d.ts} +3 -3
- package/dist/filtersFns.d.ts +22 -54
- package/dist/localization.d.ts +3 -0
- package/dist/material-react-table.cjs.development.js +251 -175
- 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 +251 -175
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TableRoot.d.ts +1 -1
- package/package.json +3 -3
- package/src/MaterialReactTable.tsx +29 -24
- package/src/body/MRT_TableBodyCell.tsx +6 -2
- package/src/body/MRT_TableBodyRow.tsx +3 -1
- package/src/body/MRT_TableDetailPanel.tsx +5 -3
- package/src/buttons/MRT_CopyButton.tsx +5 -3
- package/src/buttons/MRT_ExpandButton.tsx +5 -3
- package/src/{utils.ts → column.utils.ts} +2 -1
- package/src/filtersFns.ts +47 -13
- package/src/footer/MRT_TableFooterCell.tsx +3 -1
- package/src/head/MRT_TableHeadCell.tsx +32 -30
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +5 -3
- package/src/head/MRT_TableHeadCellGrabHandle.tsx +1 -1
- package/src/inputs/MRT_FilterTextField.tsx +12 -6
- package/src/inputs/MRT_SelectCheckbox.tsx +18 -21
- package/src/localization.ts +6 -0
- package/src/menus/MRT_ColumnActionMenu.tsx +16 -15
- package/src/menus/MRT_FilterOptionMenu.tsx +105 -72
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +1 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +1 -1
- package/src/table/MRT_Table.tsx +5 -3
- package/src/table/MRT_TableContainer.tsx +5 -3
- package/src/table/MRT_TableRoot.tsx +57 -40
- package/src/toolbar/MRT_TablePagination.tsx +5 -3
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +5 -3
- package/src/toolbar/MRT_ToolbarBottom.tsx +3 -1
- package/src/toolbar/MRT_ToolbarTop.tsx +3 -1
@@ -1,3 +1,3 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
-
import { MaterialReactTableProps } from '
|
2
|
+
import type { MaterialReactTableProps } from '..';
|
3
3
|
export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => JSX.Element;
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "0.
|
2
|
+
"version": "0.26.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.",
|
@@ -31,7 +31,7 @@
|
|
31
31
|
},
|
32
32
|
"scripts": {
|
33
33
|
"analyze": "size-limit --why",
|
34
|
-
"build": "tsdx build && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table/dist && cp -r dist material-react-table-docs/node_modules/material-react-table/
|
34
|
+
"build": "tsdx build && size-limit && rm -rf material-react-table-docs/node_modules/material-react-table/dist && cp -r dist material-react-table-docs/node_modules/material-react-table/",
|
35
35
|
"build-storybook": "build-storybook",
|
36
36
|
"format": "prettier -w .",
|
37
37
|
"lint": "eslint .",
|
@@ -75,7 +75,7 @@
|
|
75
75
|
"@types/react": "^18.0.15",
|
76
76
|
"@types/react-dom": "^18.0.6",
|
77
77
|
"babel-loader": "^8.2.5",
|
78
|
-
"eslint": "^8.
|
78
|
+
"eslint": "^8.20.0",
|
79
79
|
"eslint-plugin-react-hooks": "^4.6.0",
|
80
80
|
"husky": "^8.0.1",
|
81
81
|
"prettier": "^2.7.1",
|
@@ -49,19 +49,6 @@ import { MRT_SortingFns } from './sortingFns';
|
|
49
49
|
|
50
50
|
type LiteralUnion<T extends U, U = string> = T | (U & Record<never, never>);
|
51
51
|
|
52
|
-
export type MRT_TableOptions<TData extends Record<string, any> = {}> = Partial<
|
53
|
-
Omit<
|
54
|
-
TableOptions<TData>,
|
55
|
-
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
56
|
-
>
|
57
|
-
> & {
|
58
|
-
columns: MRT_ColumnDef<TData>[];
|
59
|
-
data: TData[];
|
60
|
-
expandRowsFn?: (dataRow: TData) => TData[];
|
61
|
-
initialState?: Partial<MRT_TableState<TData>>;
|
62
|
-
state?: Partial<MRT_TableState<TData>>;
|
63
|
-
};
|
64
|
-
|
65
52
|
export interface MRT_RowModel<TData extends Record<string, any> = {}> {
|
66
53
|
flatRows: MRT_Row<TData>[];
|
67
54
|
rows: MRT_Row<TData>[];
|
@@ -218,7 +205,7 @@ export type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit<
|
|
218
205
|
*
|
219
206
|
* @example accessorKey: 'username'
|
220
207
|
*/
|
221
|
-
accessorKey?:
|
208
|
+
accessorKey?: string & keyof TData;
|
222
209
|
/**
|
223
210
|
* Specify what type of column this is. Either `data`, `display`, or `group`. Defaults to `data`.
|
224
211
|
* Leave this blank if you are just creating a normal data column.
|
@@ -411,6 +398,13 @@ export type MRT_FilterFn<TData extends Record<string, any> = {}> =
|
|
411
398
|
| FilterFn<TData>
|
412
399
|
| MRT_FilterOption;
|
413
400
|
|
401
|
+
export type MRT_DisplayColumnIds =
|
402
|
+
| 'mrt-row-drag'
|
403
|
+
| 'mrt-row-actions'
|
404
|
+
| 'mrt-row-expand'
|
405
|
+
| 'mrt-row-select'
|
406
|
+
| 'mrt-row-numbers';
|
407
|
+
|
414
408
|
/**
|
415
409
|
* `columns` and `data` props are the only required props, but there are over 150 other optional props.
|
416
410
|
*
|
@@ -421,7 +415,15 @@ export type MRT_FilterFn<TData extends Record<string, any> = {}> =
|
|
421
415
|
* @link https://www.material-react-table.com/docs/api/props
|
422
416
|
*/
|
423
417
|
export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
424
|
-
|
418
|
+
Omit<
|
419
|
+
Partial<TableOptions<TData>>,
|
420
|
+
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
421
|
+
> & {
|
422
|
+
displayColumnDefOptions?: Partial<{
|
423
|
+
[key in MRT_DisplayColumnIds]: Partial<MRT_ColumnDef>;
|
424
|
+
}>;
|
425
|
+
columns: MRT_ColumnDef<TData>[];
|
426
|
+
data: TData[];
|
425
427
|
editingMode?: 'table' | 'row' | 'cell';
|
426
428
|
enableClickToCopy?: boolean;
|
427
429
|
enableColumnActions?: boolean;
|
@@ -449,7 +451,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
449
451
|
enableToolbarTop?: boolean;
|
450
452
|
enabledColumnFilterOptions?: (MRT_FilterOption | string)[] | null;
|
451
453
|
enabledGlobalFilterOptions?: (MRT_FilterOption | string)[] | null;
|
454
|
+
expandRowsFn?: (dataRow: TData) => TData[];
|
452
455
|
icons?: Partial<MRT_Icons>;
|
456
|
+
initialState?: Partial<MRT_TableState<TData>>;
|
453
457
|
localization?: Partial<MRT_Localization>;
|
454
458
|
muiExpandAllButtonProps?:
|
455
459
|
| IconButtonProps
|
@@ -522,6 +526,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
522
526
|
table: MRT_TableInstance<TData>;
|
523
527
|
cell: MRT_Cell<TData>;
|
524
528
|
}) => SkeletonProps);
|
529
|
+
muiTableBodyProps?:
|
530
|
+
| TableBodyProps
|
531
|
+
| (({ table }: { table: MRT_TableInstance<TData> }) => TableBodyProps);
|
525
532
|
muiTableBodyRowDragHandleProps?:
|
526
533
|
| IconButtonProps
|
527
534
|
| (({
|
@@ -531,9 +538,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
531
538
|
table: MRT_TableInstance<TData>;
|
532
539
|
row: MRT_Row<TData>;
|
533
540
|
}) => IconButtonProps);
|
534
|
-
muiTableBodyProps?:
|
535
|
-
| TableBodyProps
|
536
|
-
| (({ table }: { table: MRT_TableInstance<TData> }) => TableBodyProps);
|
537
541
|
muiTableBodyRowProps?:
|
538
542
|
| TableRowProps
|
539
543
|
| (({
|
@@ -685,6 +689,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
685
689
|
onCurrentGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
|
686
690
|
onCurrentHoveredColumnChange?: OnChangeFn<MRT_Column<TData> | null>;
|
687
691
|
onCurrentHoveredRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
692
|
+
onDensityChange?: OnChangeFn<boolean>;
|
688
693
|
onEditRowSubmit?: ({
|
689
694
|
row,
|
690
695
|
table,
|
@@ -692,7 +697,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
692
697
|
row: MRT_Row<TData>;
|
693
698
|
table: MRT_TableInstance<TData>;
|
694
699
|
}) => Promise<void> | void;
|
695
|
-
onDensityChange?: OnChangeFn<boolean>;
|
696
700
|
onIsFullScreenChange?: OnChangeFn<boolean>;
|
697
701
|
onRowDrop?: ({
|
698
702
|
event,
|
@@ -738,11 +742,6 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
738
742
|
}: {
|
739
743
|
table: MRT_TableInstance<TData>;
|
740
744
|
}) => ReactNode;
|
741
|
-
renderToolbarTopCustomActions?: ({
|
742
|
-
table,
|
743
|
-
}: {
|
744
|
-
table: MRT_TableInstance<TData>;
|
745
|
-
}) => ReactNode;
|
746
745
|
renderToolbarInternalActions?: ({
|
747
746
|
table,
|
748
747
|
MRT_ToggleGlobalFilterButton,
|
@@ -768,9 +767,15 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
768
767
|
IconButtonProps & { table: MRT_TableInstance<TData> }
|
769
768
|
>;
|
770
769
|
}) => ReactNode;
|
770
|
+
renderToolbarTopCustomActions?: ({
|
771
|
+
table,
|
772
|
+
}: {
|
773
|
+
table: MRT_TableInstance<TData>;
|
774
|
+
}) => ReactNode;
|
771
775
|
rowCount?: number;
|
772
776
|
rowNumberMode?: 'original' | 'static';
|
773
777
|
selectAllMode?: 'all' | 'page';
|
778
|
+
state?: Partial<MRT_TableState<TData>>;
|
774
779
|
tableId?: string;
|
775
780
|
virtualizerProps?: Partial<VirtualizerOptions<HTMLDivElement>>;
|
776
781
|
};
|
@@ -129,7 +129,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
129
129
|
|
130
130
|
const handleDragEnter = (_e: DragEvent) => {
|
131
131
|
if (enableColumnOrdering && currentDraggingColumn) {
|
132
|
-
setCurrentHoveredColumn(
|
132
|
+
setCurrentHoveredColumn(
|
133
|
+
columnDef.enableColumnOrdering !== false ? column : null,
|
134
|
+
);
|
133
135
|
}
|
134
136
|
};
|
135
137
|
|
@@ -222,7 +224,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
222
224
|
: `${darken(theme.palette.background.default, 0.07)} !important`
|
223
225
|
: undefined,
|
224
226
|
},
|
225
|
-
...(tableCellProps?.sx
|
227
|
+
...(tableCellProps?.sx instanceof Function
|
228
|
+
? tableCellProps.sx(theme)
|
229
|
+
: (tableCellProps?.sx as any)),
|
226
230
|
...draggingBorders,
|
227
231
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
228
232
|
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
@@ -70,7 +70,9 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
70
70
|
: `${darken(theme.palette.background.default, 0.05)}`
|
71
71
|
: undefined,
|
72
72
|
},
|
73
|
-
...(tableRowProps?.sx
|
73
|
+
...(tableRowProps?.sx instanceof Function
|
74
|
+
? tableRowProps.sx(theme)
|
75
|
+
: (tableRowProps?.sx as any)),
|
74
76
|
...draggingBorders,
|
75
77
|
})}
|
76
78
|
>
|
@@ -32,14 +32,16 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
|
|
32
32
|
<TableCell
|
33
33
|
colSpan={getVisibleLeafColumns().length}
|
34
34
|
{...tableCellProps}
|
35
|
-
sx={{
|
35
|
+
sx={(theme) => ({
|
36
36
|
borderBottom: !row.getIsExpanded() ? 'none' : undefined,
|
37
37
|
pb: row.getIsExpanded() ? '1rem' : 0,
|
38
38
|
pt: row.getIsExpanded() ? '1rem' : 0,
|
39
39
|
transition: 'all 0.2s ease-in-out',
|
40
40
|
width: `${table.getTotalSize()}px`,
|
41
|
-
...tableCellProps?.sx
|
42
|
-
|
41
|
+
...(tableCellProps?.sx instanceof Function
|
42
|
+
? tableCellProps.sx(theme)
|
43
|
+
: (tableCellProps?.sx as any)),
|
44
|
+
})}
|
43
45
|
>
|
44
46
|
{renderDetailPanel && (
|
45
47
|
<Collapse in={row.getIsExpanded()}>
|
@@ -55,7 +55,7 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
55
55
|
type="button"
|
56
56
|
variant="text"
|
57
57
|
{...buttonProps}
|
58
|
-
sx={{
|
58
|
+
sx={(theme) => ({
|
59
59
|
backgroundColor: 'transparent',
|
60
60
|
border: 'none',
|
61
61
|
color: 'inherit',
|
@@ -67,8 +67,10 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
67
67
|
minWidth: 'unset',
|
68
68
|
textAlign: 'inherit',
|
69
69
|
textTransform: 'inherit',
|
70
|
-
...buttonProps?.sx
|
71
|
-
|
70
|
+
...(buttonProps?.sx instanceof Function
|
71
|
+
? buttonProps.sx(theme)
|
72
|
+
: (buttonProps?.sx as any)),
|
73
|
+
})}
|
72
74
|
>
|
73
75
|
{children}
|
74
76
|
</Button>
|
@@ -41,11 +41,13 @@ export const MRT_ExpandButton: FC<Props> = ({ row, table }) => {
|
|
41
41
|
disabled={!row.getCanExpand() && !renderDetailPanel}
|
42
42
|
onClick={handleToggleExpand}
|
43
43
|
{...iconButtonProps}
|
44
|
-
sx={{
|
44
|
+
sx={(theme) => ({
|
45
45
|
height: density === 'compact' ? '1.75rem' : '2.25rem',
|
46
46
|
width: density === 'compact' ? '1.75rem' : '2.25rem',
|
47
|
-
...iconButtonProps?.sx
|
48
|
-
|
47
|
+
...(iconButtonProps?.sx instanceof Function
|
48
|
+
? iconButtonProps.sx(theme)
|
49
|
+
: (iconButtonProps?.sx as any)),
|
50
|
+
})}
|
49
51
|
>
|
50
52
|
<ExpandMoreIcon
|
51
53
|
style={{
|
@@ -4,6 +4,7 @@ import {
|
|
4
4
|
MRT_Column,
|
5
5
|
MRT_ColumnDef,
|
6
6
|
MRT_DefinedColumnDef,
|
7
|
+
MRT_DisplayColumnIds,
|
7
8
|
MRT_FilterOption,
|
8
9
|
} from '.';
|
9
10
|
import { MRT_FilterFns } from './filtersFns';
|
@@ -92,7 +93,7 @@ export const getLeadingDisplayColumnIds = <
|
|
92
93
|
'mrt-row-expand',
|
93
94
|
props.enableRowSelection && 'mrt-row-select',
|
94
95
|
props.enableRowNumbers && 'mrt-row-numbers',
|
95
|
-
].filter(Boolean) as
|
96
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
96
97
|
|
97
98
|
export const getTrailingDisplayColumnIds = <
|
98
99
|
TData extends Record<string, any> = {},
|
package/src/filtersFns.ts
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
import { rankItem, rankings, RankingInfo } from '@tanstack/match-sorter-utils';
|
2
2
|
import { filterFns, Row } from '@tanstack/react-table';
|
3
3
|
|
4
|
-
|
4
|
+
const fuzzy = <TData extends Record<string, any> = {}>(
|
5
5
|
row: Row<TData>,
|
6
6
|
columnId: string,
|
7
7
|
filterValue: string | number,
|
@@ -16,7 +16,7 @@ export const fuzzy = <TData extends Record<string, any> = {}>(
|
|
16
16
|
|
17
17
|
fuzzy.autoRemove = (val: any) => !val;
|
18
18
|
|
19
|
-
|
19
|
+
const contains = <TData extends Record<string, any> = {}>(
|
20
20
|
row: Row<TData>,
|
21
21
|
id: string,
|
22
22
|
filterValue: string | number,
|
@@ -30,7 +30,7 @@ export const contains = <TData extends Record<string, any> = {}>(
|
|
30
30
|
|
31
31
|
contains.autoRemove = (val: any) => !val;
|
32
32
|
|
33
|
-
|
33
|
+
const startsWith = <TData extends Record<string, any> = {}>(
|
34
34
|
row: Row<TData>,
|
35
35
|
id: string,
|
36
36
|
filterValue: string | number,
|
@@ -44,7 +44,7 @@ export const startsWith = <TData extends Record<string, any> = {}>(
|
|
44
44
|
|
45
45
|
startsWith.autoRemove = (val: any) => !val;
|
46
46
|
|
47
|
-
|
47
|
+
const endsWith = <TData extends Record<string, any> = {}>(
|
48
48
|
row: Row<TData>,
|
49
49
|
id: string,
|
50
50
|
filterValue: string | number,
|
@@ -58,7 +58,7 @@ export const endsWith = <TData extends Record<string, any> = {}>(
|
|
58
58
|
|
59
59
|
endsWith.autoRemove = (val: any) => !val;
|
60
60
|
|
61
|
-
|
61
|
+
const equals = <TData extends Record<string, any> = {}>(
|
62
62
|
row: Row<TData>,
|
63
63
|
id: string,
|
64
64
|
filterValue: string | number,
|
@@ -68,7 +68,7 @@ export const equals = <TData extends Record<string, any> = {}>(
|
|
68
68
|
|
69
69
|
equals.autoRemove = (val: any) => !val;
|
70
70
|
|
71
|
-
|
71
|
+
const notEquals = <TData extends Record<string, any> = {}>(
|
72
72
|
row: Row<TData>,
|
73
73
|
id: string,
|
74
74
|
filterValue: string | number,
|
@@ -78,31 +78,47 @@ export const notEquals = <TData extends Record<string, any> = {}>(
|
|
78
78
|
|
79
79
|
notEquals.autoRemove = (val: any) => !val;
|
80
80
|
|
81
|
-
|
81
|
+
const greaterThan = <TData extends Record<string, any> = {}>(
|
82
82
|
row: Row<TData>,
|
83
83
|
id: string,
|
84
84
|
filterValue: string | number,
|
85
85
|
) =>
|
86
86
|
!isNaN(+filterValue) && !isNaN(+row.getValue<string | number>(id))
|
87
|
-
? +row.getValue<string | number>(id)
|
87
|
+
? +row.getValue<string | number>(id) > +filterValue
|
88
88
|
: row.getValue<string | number>(id).toString().toLowerCase().trim() >
|
89
89
|
filterValue.toString().toLowerCase().trim();
|
90
90
|
|
91
91
|
greaterThan.autoRemove = (val: any) => !val;
|
92
92
|
|
93
|
-
|
93
|
+
const greaterThanOrEqualTo = <TData extends Record<string, any> = {}>(
|
94
|
+
row: Row<TData>,
|
95
|
+
id: string,
|
96
|
+
filterValue: string | number,
|
97
|
+
) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
|
98
|
+
|
99
|
+
greaterThanOrEqualTo.autoRemove = (val: any) => !val;
|
100
|
+
|
101
|
+
const lessThan = <TData extends Record<string, any> = {}>(
|
94
102
|
row: Row<TData>,
|
95
103
|
id: string,
|
96
104
|
filterValue: string | number,
|
97
105
|
) =>
|
98
106
|
!isNaN(+filterValue) && !isNaN(+row.getValue<string | number>(id))
|
99
|
-
? +row.getValue<string | number>(id)
|
107
|
+
? +row.getValue<string | number>(id) < +filterValue
|
100
108
|
: row.getValue<string | number>(id).toString().toLowerCase().trim() <
|
101
109
|
filterValue.toString().toLowerCase().trim();
|
102
110
|
|
103
111
|
lessThan.autoRemove = (val: any) => !val;
|
104
112
|
|
105
|
-
|
113
|
+
const lessThanOrEqualTo = <TData extends Record<string, any> = {}>(
|
114
|
+
row: Row<TData>,
|
115
|
+
id: string,
|
116
|
+
filterValue: string | number,
|
117
|
+
) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
|
118
|
+
|
119
|
+
lessThanOrEqualTo.autoRemove = (val: any) => !val;
|
120
|
+
|
121
|
+
const between = <TData extends Record<string, any> = {}>(
|
106
122
|
row: Row<TData>,
|
107
123
|
id: string,
|
108
124
|
filterValues: [string | number, string | number],
|
@@ -117,7 +133,22 @@ export const between = <TData extends Record<string, any> = {}>(
|
|
117
133
|
|
118
134
|
between.autoRemove = (val: any) => !val;
|
119
135
|
|
120
|
-
|
136
|
+
const betweenInclusive = <TData extends Record<string, any> = {}>(
|
137
|
+
row: Row<TData>,
|
138
|
+
id: string,
|
139
|
+
filterValues: [string | number, string | number],
|
140
|
+
) =>
|
141
|
+
((['', undefined] as any[]).includes(filterValues[0]) ||
|
142
|
+
greaterThanOrEqualTo(row, id, filterValues[0])) &&
|
143
|
+
((!isNaN(+filterValues[0]) &&
|
144
|
+
!isNaN(+filterValues[1]) &&
|
145
|
+
+filterValues[0] > +filterValues[1]) ||
|
146
|
+
(['', undefined] as any[]).includes(filterValues[1]) ||
|
147
|
+
lessThanOrEqualTo(row, id, filterValues[1]));
|
148
|
+
|
149
|
+
betweenInclusive.autoRemove = (val: any) => !val;
|
150
|
+
|
151
|
+
const empty = <TData extends Record<string, any> = {}>(
|
121
152
|
row: Row<TData>,
|
122
153
|
id: string,
|
123
154
|
_filterValue: string | number,
|
@@ -125,7 +156,7 @@ export const empty = <TData extends Record<string, any> = {}>(
|
|
125
156
|
|
126
157
|
empty.autoRemove = (val: any) => !val;
|
127
158
|
|
128
|
-
|
159
|
+
const notEmpty = <TData extends Record<string, any> = {}>(
|
129
160
|
row: Row<TData>,
|
130
161
|
id: string,
|
131
162
|
_filterValue: string | number,
|
@@ -136,13 +167,16 @@ notEmpty.autoRemove = (val: any) => !val;
|
|
136
167
|
export const MRT_FilterFns = {
|
137
168
|
...filterFns,
|
138
169
|
between,
|
170
|
+
betweenInclusive,
|
139
171
|
contains,
|
140
172
|
empty,
|
141
173
|
endsWith,
|
142
174
|
equals,
|
143
175
|
fuzzy,
|
144
176
|
greaterThan,
|
177
|
+
greaterThanOrEqualTo,
|
145
178
|
lessThan,
|
179
|
+
lessThanOrEqualTo,
|
146
180
|
notEmpty,
|
147
181
|
notEquals,
|
148
182
|
startsWith,
|
@@ -56,7 +56,9 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, table }) => {
|
|
56
56
|
transition: `all ${enableColumnResizing ? '10ms' : '0.2s'} ease-in-out`,
|
57
57
|
width: column.getSize(),
|
58
58
|
verticalAlign: 'text-top',
|
59
|
-
...(tableCellProps?.sx
|
59
|
+
...(tableCellProps?.sx instanceof Function
|
60
|
+
? tableCellProps.sx(theme)
|
61
|
+
: (tableCellProps?.sx as any)),
|
60
62
|
})}
|
61
63
|
>
|
62
64
|
<>
|
@@ -48,13 +48,6 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
48
48
|
...mcTableHeadCellProps,
|
49
49
|
};
|
50
50
|
|
51
|
-
const headerElement = ((columnDef?.Header instanceof Function
|
52
|
-
? columnDef?.Header?.({
|
53
|
-
header,
|
54
|
-
table,
|
55
|
-
})
|
56
|
-
: columnDef?.Header) ?? columnDef.header) as ReactNode;
|
57
|
-
|
58
51
|
const getIsLastLeftPinnedColumn = () => {
|
59
52
|
return (
|
60
53
|
column.getIsPinned() === 'left' &&
|
@@ -74,12 +67,12 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
74
67
|
|
75
68
|
const handleDragEnter = (_e: DragEvent) => {
|
76
69
|
if (enableColumnOrdering && currentDraggingColumn) {
|
77
|
-
setCurrentHoveredColumn(
|
70
|
+
setCurrentHoveredColumn(
|
71
|
+
columnDef.enableColumnOrdering !== false ? column : null,
|
72
|
+
);
|
78
73
|
}
|
79
74
|
};
|
80
75
|
|
81
|
-
const tableHeadCellRef = React.useRef<HTMLTableCellElement>(null);
|
82
|
-
|
83
76
|
const draggingBorder =
|
84
77
|
currentDraggingColumn?.id === column.id
|
85
78
|
? `1px dashed ${theme.palette.divider}`
|
@@ -95,6 +88,15 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
95
88
|
}
|
96
89
|
: undefined;
|
97
90
|
|
91
|
+
const headerElement = ((columnDef?.Header instanceof Function
|
92
|
+
? columnDef?.Header?.({
|
93
|
+
header,
|
94
|
+
table,
|
95
|
+
})
|
96
|
+
: columnDef?.Header) ?? columnDef.header) as ReactNode;
|
97
|
+
|
98
|
+
const tableHeadCellRef = React.useRef<HTMLTableCellElement>(null);
|
99
|
+
|
98
100
|
return (
|
99
101
|
<TableCell
|
100
102
|
align={columnDefType === 'group' ? 'center' : 'left'}
|
@@ -153,23 +155,23 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
153
155
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
154
156
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
155
157
|
userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
|
156
|
-
verticalAlign: '
|
158
|
+
verticalAlign: 'top',
|
157
159
|
zIndex:
|
158
160
|
column.getIsResizing() || currentDraggingColumn?.id === column.id
|
159
161
|
? 3
|
160
162
|
: column.getIsPinned() && columnDefType !== 'group'
|
161
163
|
? 2
|
162
164
|
: 1,
|
163
|
-
...(tableCellProps?.sx
|
165
|
+
...(tableCellProps?.sx instanceof Function
|
166
|
+
? tableCellProps.sx(theme)
|
167
|
+
: (tableCellProps?.sx as any)),
|
164
168
|
...draggingBorders,
|
165
169
|
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
166
170
|
minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
|
167
171
|
width: header.getSize(),
|
168
172
|
})}
|
169
173
|
>
|
170
|
-
{header.isPlaceholder ? null :
|
171
|
-
headerElement
|
172
|
-
) : (
|
174
|
+
{header.isPlaceholder ? null : (
|
173
175
|
<Box
|
174
176
|
sx={{
|
175
177
|
alignItems: 'flex-start',
|
@@ -195,16 +197,16 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
195
197
|
}}
|
196
198
|
>
|
197
199
|
{headerElement}
|
198
|
-
{
|
200
|
+
{column.getCanSort() && (
|
199
201
|
<MRT_TableHeadCellSortLabel header={header} table={table} />
|
200
202
|
)}
|
201
|
-
{
|
203
|
+
{column.getCanFilter() && (
|
202
204
|
<MRT_TableHeadCellFilterLabel header={header} table={table} />
|
203
205
|
)}
|
204
206
|
</Box>
|
205
|
-
|
206
|
-
{
|
207
|
-
((enableColumnDragging &&
|
207
|
+
{columnDefType !== 'group' && (
|
208
|
+
<Box sx={{ whiteSpace: 'nowrap' }}>
|
209
|
+
{((enableColumnDragging &&
|
208
210
|
columnDef.enableColumnDragging !== false) ||
|
209
211
|
(enableColumnOrdering &&
|
210
212
|
columnDef.enableColumnOrdering !== false) ||
|
@@ -215,21 +217,21 @@ export const MRT_TableHeadCell: FC<Props> = ({ header, table }) => {
|
|
215
217
|
tableHeadCellRef={tableHeadCellRef}
|
216
218
|
/>
|
217
219
|
)}
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
220
|
+
{(enableColumnActions || columnDef.enableColumnActions) &&
|
221
|
+
columnDef.enableColumnActions !== false && (
|
222
|
+
<MRT_TableHeadCellColumnActionsButton
|
223
|
+
header={header}
|
224
|
+
table={table}
|
225
|
+
/>
|
226
|
+
)}
|
227
|
+
</Box>
|
228
|
+
)}
|
227
229
|
{column.getCanResize() && (
|
228
230
|
<MRT_TableHeadCellResizeHandle header={header} table={table} />
|
229
231
|
)}
|
230
232
|
</Box>
|
231
233
|
)}
|
232
|
-
{
|
234
|
+
{column.getCanFilter() && (
|
233
235
|
<MRT_TableHeadCellFilterContainer header={header} table={table} />
|
234
236
|
)}
|
235
237
|
</TableCell>
|
@@ -62,7 +62,7 @@ export const MRT_TableHeadCellColumnActionsButton: FC<Props> = ({
|
|
62
62
|
onClick={handleClick}
|
63
63
|
size="small"
|
64
64
|
{...iconButtonProps}
|
65
|
-
sx={{
|
65
|
+
sx={(theme) => ({
|
66
66
|
height: '2rem',
|
67
67
|
mt: '-0.2rem',
|
68
68
|
opacity: 0.5,
|
@@ -71,8 +71,10 @@ export const MRT_TableHeadCellColumnActionsButton: FC<Props> = ({
|
|
71
71
|
'&:hover': {
|
72
72
|
opacity: 1,
|
73
73
|
},
|
74
|
-
...iconButtonProps
|
75
|
-
|
74
|
+
...(iconButtonProps?.sx instanceof Function
|
75
|
+
? iconButtonProps.sx(theme)
|
76
|
+
: (iconButtonProps?.sx as any)),
|
77
|
+
})}
|
76
78
|
>
|
77
79
|
<MoreVertIcon />
|
78
80
|
</IconButton>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { DragEvent, FC, RefObject } from 'react';
|
2
2
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
3
|
-
import { reorderColumn } from '../utils';
|
3
|
+
import { reorderColumn } from '../column.utils';
|
4
4
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
5
5
|
|
6
6
|
interface Props {
|
@@ -73,14 +73,18 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
73
73
|
|
74
74
|
const handleChangeDebounced = useCallback(
|
75
75
|
debounce((event: ChangeEvent<HTMLInputElement>) => {
|
76
|
+
let value =
|
77
|
+
textFieldProps.type === 'date'
|
78
|
+
? new Date(event.target.value)
|
79
|
+
: event.target.value;
|
76
80
|
if (inputIndex !== undefined) {
|
77
|
-
column.setFilterValue((old: [string, string]) => {
|
81
|
+
column.setFilterValue((old: [string, string | Date]) => {
|
78
82
|
const newFilterValues = old ?? ['', ''];
|
79
|
-
newFilterValues[inputIndex] =
|
83
|
+
newFilterValues[inputIndex] = value;
|
80
84
|
return newFilterValues;
|
81
85
|
});
|
82
86
|
} else {
|
83
|
-
column.setFilterValue(
|
87
|
+
column.setFilterValue(value ?? undefined);
|
84
88
|
}
|
85
89
|
}, 200),
|
86
90
|
[],
|
@@ -255,7 +259,7 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
255
259
|
),
|
256
260
|
}}
|
257
261
|
{...textFieldProps}
|
258
|
-
sx={{
|
262
|
+
sx={(theme) => ({
|
259
263
|
m: '-0.25rem',
|
260
264
|
p: 0,
|
261
265
|
minWidth: !filterChipLabel ? '8rem' : 'auto',
|
@@ -263,8 +267,10 @@ export const MRT_FilterTextField: FC<Props> = ({
|
|
263
267
|
'& .MuiSelect-icon': {
|
264
268
|
mr: '1.5rem',
|
265
269
|
},
|
266
|
-
...textFieldProps?.sx
|
267
|
-
|
270
|
+
...(textFieldProps?.sx instanceof Function
|
271
|
+
? textFieldProps.sx(theme)
|
272
|
+
: (textFieldProps?.sx as any)),
|
273
|
+
})}
|
268
274
|
>
|
269
275
|
{isSelectFilter && (
|
270
276
|
<MenuItem divider disabled={!filterValue} value="">
|