material-react-table 0.21.0 → 0.22.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 +90 -18
- package/dist/MaterialReactTable.d.ts +159 -153
- package/dist/body/MRT_TableBody.d.ts +3 -2
- package/dist/body/MRT_TableBodyCell.d.ts +3 -2
- package/dist/body/MRT_TableBodyRow.d.ts +3 -2
- package/dist/buttons/MRT_GrabHandleButton.d.ts +3 -2
- package/dist/filtersFns.d.ts +22 -22
- package/dist/head/MRT_TableHead.d.ts +4 -2
- package/dist/head/MRT_TableHeadCell.d.ts +4 -6
- package/dist/head/MRT_TableHeadRow.d.ts +4 -2
- package/dist/material-react-table.cjs.development.js +189 -4422
- 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 +152 -148
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +3 -1
- package/dist/sortingFns.d.ts +2 -2
- package/dist/table/MRT_TableRoot.d.ts +1 -1
- package/dist/utils.d.ts +7 -7
- package/package.json +6 -8
- package/src/MaterialReactTable.tsx +189 -174
- package/src/body/MRT_TableBody.tsx +9 -3
- package/src/body/MRT_TableBodyCell.tsx +15 -17
- package/src/body/MRT_TableBodyRow.tsx +10 -3
- package/src/buttons/MRT_CopyButton.tsx +0 -1
- package/src/buttons/MRT_GrabHandleButton.tsx +12 -5
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -3
- package/src/filtersFns.ts +24 -24
- package/src/head/MRT_TableHead.tsx +11 -3
- package/src/head/MRT_TableHeadCell.tsx +49 -20
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +2 -2
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +2 -2
- package/src/head/MRT_TableHeadRow.tsx +25 -20
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +6 -1
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +54 -27
- package/src/sortingFns.ts +6 -6
- package/src/table/MRT_Table.tsx +17 -4
- package/src/table/MRT_TableContainer.tsx +1 -1
- package/src/table/MRT_TablePaper.tsx +21 -25
- package/src/table/MRT_TableRoot.tsx +12 -13
- package/src/utils.ts +28 -22
- package/dist/head/MRT_DraggableTableHeadCell.d.ts +0 -8
- package/src/head/MRT_DraggableTableHeadCell.tsx +0 -43
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
import React, { FC, RefObject, useMemo } from 'react';
|
|
1
|
+
import React, { Dispatch, FC, RefObject, SetStateAction, 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 { rankGlobalFuzzy } from '../sortingFns';
|
|
6
|
-
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
6
|
+
import type { MRT_Column, MRT_Row, MRT_TableInstance } from '..';
|
|
7
7
|
|
|
8
8
|
interface Props {
|
|
9
9
|
table: MRT_TableInstance;
|
|
10
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
10
11
|
tableContainerRef: RefObject<HTMLDivElement>;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export const MRT_TableBody: FC<Props> = ({
|
|
14
|
+
export const MRT_TableBody: FC<Props> = ({
|
|
15
|
+
setCurrentHoveredColumn,
|
|
16
|
+
table,
|
|
17
|
+
tableContainerRef,
|
|
18
|
+
}) => {
|
|
14
19
|
const {
|
|
15
20
|
getRowModel,
|
|
16
21
|
getPrePaginationRowModel,
|
|
@@ -103,6 +108,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
103
108
|
rowIndex={
|
|
104
109
|
enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
|
|
105
110
|
}
|
|
111
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
106
112
|
table={table}
|
|
107
113
|
/>
|
|
108
114
|
);
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
Dispatch,
|
|
3
|
+
DragEvent,
|
|
4
|
+
FC,
|
|
5
|
+
MouseEvent,
|
|
6
|
+
SetStateAction,
|
|
7
|
+
useMemo,
|
|
8
|
+
} from 'react';
|
|
3
9
|
import { alpha, darken, lighten, Skeleton, TableCell } from '@mui/material';
|
|
4
10
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
5
11
|
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
|
6
|
-
import { reorderColumn } from '../utils';
|
|
7
12
|
import type { MRT_Cell, MRT_Column, MRT_TableInstance } from '..';
|
|
8
13
|
|
|
9
14
|
interface Props {
|
|
10
15
|
cell: MRT_Cell;
|
|
11
16
|
enableHover?: boolean;
|
|
12
17
|
rowIndex: number;
|
|
18
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
13
19
|
table: MRT_TableInstance;
|
|
14
20
|
}
|
|
15
21
|
|
|
@@ -17,6 +23,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
17
23
|
cell,
|
|
18
24
|
enableHover,
|
|
19
25
|
rowIndex,
|
|
26
|
+
setCurrentHoveredColumn,
|
|
20
27
|
table,
|
|
21
28
|
}) => {
|
|
22
29
|
const {
|
|
@@ -24,7 +31,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
24
31
|
options: {
|
|
25
32
|
editingMode,
|
|
26
33
|
enableClickToCopy,
|
|
27
|
-
enableColumnOrdering,
|
|
28
34
|
enableEditing,
|
|
29
35
|
enableRowNumbers,
|
|
30
36
|
muiTableBodyCellProps,
|
|
@@ -32,11 +38,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
32
38
|
rowNumberMode,
|
|
33
39
|
tableId,
|
|
34
40
|
},
|
|
35
|
-
setColumnOrder,
|
|
36
41
|
setCurrentEditingCell,
|
|
37
42
|
} = table;
|
|
38
43
|
const {
|
|
39
|
-
columnOrder,
|
|
40
44
|
currentEditingCell,
|
|
41
45
|
currentEditingRow,
|
|
42
46
|
density,
|
|
@@ -47,14 +51,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
47
51
|
const { columnDef } = column;
|
|
48
52
|
const { columnDefType } = columnDef;
|
|
49
53
|
|
|
50
|
-
const [, dropRef] = useDrop({
|
|
51
|
-
accept: 'column',
|
|
52
|
-
drop: (movingColumn: MRT_Column) => {
|
|
53
|
-
const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
|
|
54
|
-
setColumnOrder(newColumnOrder);
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
|
|
58
54
|
const mTableCellBodyProps =
|
|
59
55
|
muiTableBodyCellProps instanceof Function
|
|
60
56
|
? muiTableBodyCellProps({ cell, table })
|
|
@@ -125,13 +121,15 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
125
121
|
);
|
|
126
122
|
};
|
|
127
123
|
|
|
124
|
+
const handleDragEnter = (_e: DragEvent) => {
|
|
125
|
+
setCurrentHoveredColumn(columnDefType === 'data' ? column : null);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
128
|
return (
|
|
129
129
|
<TableCell
|
|
130
130
|
onDoubleClick={handleDoubleClick}
|
|
131
|
+
onDragEnter={handleDragEnter}
|
|
131
132
|
{...tableCellProps}
|
|
132
|
-
ref={
|
|
133
|
-
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
134
|
-
}
|
|
135
133
|
sx={(theme) => ({
|
|
136
134
|
backgroundColor: column.getIsPinned()
|
|
137
135
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
@@ -1,16 +1,22 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { Dispatch, FC, SetStateAction } from 'react';
|
|
2
2
|
import { darken, lighten, TableRow } from '@mui/material';
|
|
3
3
|
import { MRT_TableBodyCell } from './MRT_TableBodyCell';
|
|
4
4
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
|
5
|
-
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
5
|
+
import type { MRT_Column, MRT_Row, MRT_TableInstance } from '..';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
row: MRT_Row;
|
|
9
9
|
rowIndex: number;
|
|
10
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
10
11
|
table: MRT_TableInstance;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export const MRT_TableBodyRow: FC<Props> = ({
|
|
14
|
+
export const MRT_TableBodyRow: FC<Props> = ({
|
|
15
|
+
row,
|
|
16
|
+
rowIndex,
|
|
17
|
+
setCurrentHoveredColumn,
|
|
18
|
+
table,
|
|
19
|
+
}) => {
|
|
14
20
|
const {
|
|
15
21
|
getIsSomeColumnsPinned,
|
|
16
22
|
options: { muiTableBodyRowProps, renderDetailPanel },
|
|
@@ -47,6 +53,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, table }) => {
|
|
|
47
53
|
key={cell.id}
|
|
48
54
|
enableHover={tableRowProps?.hover !== false}
|
|
49
55
|
rowIndex={rowIndex}
|
|
56
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
50
57
|
table={table}
|
|
51
58
|
/>
|
|
52
59
|
))}
|
|
@@ -50,7 +50,6 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
|
50
50
|
title={copied ? localization.copiedToClipboard : localization.clickToCopy}
|
|
51
51
|
>
|
|
52
52
|
<Button
|
|
53
|
-
aria-label={localization.clickToCopy}
|
|
54
53
|
onClick={() => handleCopy(cell.getValue())}
|
|
55
54
|
size="small"
|
|
56
55
|
type="button"
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
import { IconButton, Tooltip } from '@mui/material';
|
|
2
|
-
import React, {
|
|
2
|
+
import React, { DragEventHandler, FC } from 'react';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
|
|
6
|
+
handleDragStart: DragEventHandler<HTMLButtonElement>;
|
|
7
|
+
handleDragEnd: DragEventHandler<HTMLButtonElement>;
|
|
7
8
|
table: MRT_TableInstance;
|
|
8
9
|
}
|
|
9
10
|
|
|
10
|
-
export const MRT_GrabHandleButton: FC<Props> =
|
|
11
|
+
export const MRT_GrabHandleButton: FC<Props> = ({
|
|
12
|
+
handleDragStart,
|
|
13
|
+
handleDragEnd,
|
|
14
|
+
table,
|
|
15
|
+
}) => {
|
|
11
16
|
const {
|
|
12
17
|
options: {
|
|
13
18
|
icons: { DragHandleIcon },
|
|
@@ -25,7 +30,9 @@ export const MRT_GrabHandleButton: FC<Props> = forwardRef(({ table }, ref) => {
|
|
|
25
30
|
>
|
|
26
31
|
<IconButton
|
|
27
32
|
disableRipple
|
|
28
|
-
|
|
33
|
+
draggable="true"
|
|
34
|
+
onDragStart={handleDragStart}
|
|
35
|
+
onDragEnd={handleDragEnd}
|
|
29
36
|
size="small"
|
|
30
37
|
sx={{
|
|
31
38
|
cursor: 'grab',
|
|
@@ -46,4 +53,4 @@ export const MRT_GrabHandleButton: FC<Props> = forwardRef(({ table }, ref) => {
|
|
|
46
53
|
</IconButton>
|
|
47
54
|
</Tooltip>
|
|
48
55
|
);
|
|
49
|
-
}
|
|
56
|
+
};
|
|
@@ -15,10 +15,10 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ table, ...rest }) => {
|
|
|
15
15
|
},
|
|
16
16
|
setShowFilters,
|
|
17
17
|
} = table;
|
|
18
|
-
const {
|
|
18
|
+
const { showColumnFilters } = getState();
|
|
19
19
|
|
|
20
20
|
const handleToggleShowFilters = () => {
|
|
21
|
-
setShowFilters(!
|
|
21
|
+
setShowFilters(!showColumnFilters);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
return (
|
|
@@ -28,7 +28,7 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ table, ...rest }) => {
|
|
|
28
28
|
onClick={handleToggleShowFilters}
|
|
29
29
|
{...rest}
|
|
30
30
|
>
|
|
31
|
-
{
|
|
31
|
+
{showColumnFilters ? <FilterListOffIcon /> : <FilterListIcon />}
|
|
32
32
|
</IconButton>
|
|
33
33
|
</Tooltip>
|
|
34
34
|
);
|
package/src/filtersFns.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { rankItem, rankings, RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
2
|
import { filterFns, Row } from '@tanstack/react-table';
|
|
3
3
|
|
|
4
|
-
export const fuzzy = <
|
|
5
|
-
row: Row<
|
|
4
|
+
export const fuzzy = <TData extends Record<string, any> = {}>(
|
|
5
|
+
row: Row<TData>,
|
|
6
6
|
columnId: string,
|
|
7
|
-
filterValue: string,
|
|
7
|
+
filterValue: string | number,
|
|
8
8
|
addMeta: (item: RankingInfo) => void,
|
|
9
9
|
) => {
|
|
10
|
-
const itemRank = rankItem(row.getValue(columnId), filterValue, {
|
|
10
|
+
const itemRank = rankItem(row.getValue(columnId), filterValue as string, {
|
|
11
11
|
threshold: rankings.MATCHES,
|
|
12
12
|
});
|
|
13
13
|
addMeta(itemRank);
|
|
@@ -16,8 +16,8 @@ export const fuzzy = <D extends Record<string, any> = {}>(
|
|
|
16
16
|
|
|
17
17
|
fuzzy.autoRemove = (val: any) => !val;
|
|
18
18
|
|
|
19
|
-
export const contains = <
|
|
20
|
-
row: Row<
|
|
19
|
+
export const contains = <TData extends Record<string, any> = {}>(
|
|
20
|
+
row: Row<TData>,
|
|
21
21
|
id: string,
|
|
22
22
|
filterValue: string | number,
|
|
23
23
|
) =>
|
|
@@ -30,8 +30,8 @@ export const contains = <D extends Record<string, any> = {}>(
|
|
|
30
30
|
|
|
31
31
|
contains.autoRemove = (val: any) => !val;
|
|
32
32
|
|
|
33
|
-
export const startsWith = <
|
|
34
|
-
row: Row<
|
|
33
|
+
export const startsWith = <TData extends Record<string, any> = {}>(
|
|
34
|
+
row: Row<TData>,
|
|
35
35
|
id: string,
|
|
36
36
|
filterValue: string | number,
|
|
37
37
|
) =>
|
|
@@ -44,8 +44,8 @@ export const startsWith = <D extends Record<string, any> = {}>(
|
|
|
44
44
|
|
|
45
45
|
startsWith.autoRemove = (val: any) => !val;
|
|
46
46
|
|
|
47
|
-
export const endsWith = <
|
|
48
|
-
row: Row<
|
|
47
|
+
export const endsWith = <TData extends Record<string, any> = {}>(
|
|
48
|
+
row: Row<TData>,
|
|
49
49
|
id: string,
|
|
50
50
|
filterValue: string | number,
|
|
51
51
|
) =>
|
|
@@ -58,8 +58,8 @@ export const endsWith = <D extends Record<string, any> = {}>(
|
|
|
58
58
|
|
|
59
59
|
endsWith.autoRemove = (val: any) => !val;
|
|
60
60
|
|
|
61
|
-
export const equals = <
|
|
62
|
-
row: Row<
|
|
61
|
+
export const equals = <TData extends Record<string, any> = {}>(
|
|
62
|
+
row: Row<TData>,
|
|
63
63
|
id: string,
|
|
64
64
|
filterValue: string | number,
|
|
65
65
|
) =>
|
|
@@ -68,8 +68,8 @@ export const equals = <D extends Record<string, any> = {}>(
|
|
|
68
68
|
|
|
69
69
|
equals.autoRemove = (val: any) => !val;
|
|
70
70
|
|
|
71
|
-
export const notEquals = <
|
|
72
|
-
row: Row<
|
|
71
|
+
export const notEquals = <TData extends Record<string, any> = {}>(
|
|
72
|
+
row: Row<TData>,
|
|
73
73
|
id: string,
|
|
74
74
|
filterValue: string | number,
|
|
75
75
|
) =>
|
|
@@ -78,8 +78,8 @@ export const notEquals = <D extends Record<string, any> = {}>(
|
|
|
78
78
|
|
|
79
79
|
notEquals.autoRemove = (val: any) => !val;
|
|
80
80
|
|
|
81
|
-
export const greaterThan = <
|
|
82
|
-
row: Row<
|
|
81
|
+
export const greaterThan = <TData extends Record<string, any> = {}>(
|
|
82
|
+
row: Row<TData>,
|
|
83
83
|
id: string,
|
|
84
84
|
filterValue: string | number,
|
|
85
85
|
) =>
|
|
@@ -90,8 +90,8 @@ export const greaterThan = <D extends Record<string, any> = {}>(
|
|
|
90
90
|
|
|
91
91
|
greaterThan.autoRemove = (val: any) => !val;
|
|
92
92
|
|
|
93
|
-
export const lessThan = <
|
|
94
|
-
row: Row<
|
|
93
|
+
export const lessThan = <TData extends Record<string, any> = {}>(
|
|
94
|
+
row: Row<TData>,
|
|
95
95
|
id: string,
|
|
96
96
|
filterValue: string | number,
|
|
97
97
|
) =>
|
|
@@ -102,8 +102,8 @@ export const lessThan = <D extends Record<string, any> = {}>(
|
|
|
102
102
|
|
|
103
103
|
lessThan.autoRemove = (val: any) => !val;
|
|
104
104
|
|
|
105
|
-
export const between = <
|
|
106
|
-
row: Row<
|
|
105
|
+
export const between = <TData extends Record<string, any> = {}>(
|
|
106
|
+
row: Row<TData>,
|
|
107
107
|
id: string,
|
|
108
108
|
filterValues: [string | number, string | number],
|
|
109
109
|
) =>
|
|
@@ -117,16 +117,16 @@ export const between = <D extends Record<string, any> = {}>(
|
|
|
117
117
|
|
|
118
118
|
between.autoRemove = (val: any) => !val;
|
|
119
119
|
|
|
120
|
-
export const empty = <
|
|
121
|
-
row: Row<
|
|
120
|
+
export const empty = <TData extends Record<string, any> = {}>(
|
|
121
|
+
row: Row<TData>,
|
|
122
122
|
id: string,
|
|
123
123
|
_filterValue: string | number,
|
|
124
124
|
) => !row.getValue(id).toString().trim();
|
|
125
125
|
|
|
126
126
|
empty.autoRemove = (val: any) => !val;
|
|
127
127
|
|
|
128
|
-
export const notEmpty = <
|
|
129
|
-
row: Row<
|
|
128
|
+
export const notEmpty = <TData extends Record<string, any> = {}>(
|
|
129
|
+
row: Row<TData>,
|
|
130
130
|
id: string,
|
|
131
131
|
_filterValue: string | number,
|
|
132
132
|
) => !!row.getValue(id).toString().trim();
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { Dispatch, FC, SetStateAction } from 'react';
|
|
2
2
|
import { TableHead } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadRow } from './MRT_TableHeadRow';
|
|
4
|
-
import type { MRT_TableInstance } from '..';
|
|
4
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
+
currentHoveredColumn: MRT_Column | null;
|
|
8
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
7
9
|
table: MRT_TableInstance;
|
|
8
10
|
}
|
|
9
11
|
|
|
10
|
-
export const MRT_TableHead: FC<Props> = ({
|
|
12
|
+
export const MRT_TableHead: FC<Props> = ({
|
|
13
|
+
currentHoveredColumn,
|
|
14
|
+
setCurrentHoveredColumn,
|
|
15
|
+
table,
|
|
16
|
+
}) => {
|
|
11
17
|
const {
|
|
12
18
|
getHeaderGroups,
|
|
13
19
|
options: { muiTableHeadProps },
|
|
@@ -22,6 +28,8 @@ export const MRT_TableHead: FC<Props> = ({ table }) => {
|
|
|
22
28
|
<TableHead {...tableHeadProps}>
|
|
23
29
|
{getHeaderGroups().map((headerGroup) => (
|
|
24
30
|
<MRT_TableHeadRow
|
|
31
|
+
currentHoveredColumn={currentHoveredColumn}
|
|
32
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
25
33
|
headerGroup={headerGroup as any}
|
|
26
34
|
key={headerGroup.id}
|
|
27
35
|
table={table}
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, {
|
|
2
|
+
Dispatch,
|
|
3
|
+
DragEvent,
|
|
4
|
+
FC,
|
|
5
|
+
ReactNode,
|
|
6
|
+
SetStateAction,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
2
9
|
import { Box, TableCell, Theme, alpha, lighten } from '@mui/material';
|
|
3
10
|
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
|
|
4
11
|
import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
|
|
@@ -6,24 +13,21 @@ import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
|
6
13
|
import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
|
|
7
14
|
import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
|
|
8
15
|
import { MRT_TableHeadCellColumnActionsButton } from './MRT_TableHeadCellColumnActionsButton';
|
|
9
|
-
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
16
|
+
import type { MRT_Column, MRT_Header, MRT_TableInstance } from '..';
|
|
17
|
+
import { reorderColumn } from '../utils';
|
|
10
18
|
|
|
11
19
|
interface Props {
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
currentHoveredColumn: MRT_Column | null;
|
|
21
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
14
22
|
header: MRT_Header;
|
|
15
23
|
table: MRT_TableInstance;
|
|
16
|
-
isDragging?: boolean;
|
|
17
|
-
previewRef?: Ref<HTMLTableCellElement>;
|
|
18
24
|
}
|
|
19
25
|
|
|
20
26
|
export const MRT_TableHeadCell: FC<Props> = ({
|
|
21
|
-
|
|
22
|
-
|
|
27
|
+
currentHoveredColumn,
|
|
28
|
+
setCurrentHoveredColumn,
|
|
23
29
|
header,
|
|
24
30
|
table,
|
|
25
|
-
isDragging,
|
|
26
|
-
previewRef,
|
|
27
31
|
}) => {
|
|
28
32
|
const {
|
|
29
33
|
getState,
|
|
@@ -35,8 +39,9 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
35
39
|
enableMultiSort,
|
|
36
40
|
muiTableHeadCellProps,
|
|
37
41
|
},
|
|
42
|
+
setColumnOrder,
|
|
38
43
|
} = table;
|
|
39
|
-
const {
|
|
44
|
+
const { columnOrder, density } = getState();
|
|
40
45
|
const { column } = header;
|
|
41
46
|
const { columnDef } = column;
|
|
42
47
|
const { columnDefType } = columnDef;
|
|
@@ -80,32 +85,57 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
80
85
|
);
|
|
81
86
|
};
|
|
82
87
|
|
|
88
|
+
const tableHeadCellRef = React.useRef<HTMLElement>(null);
|
|
89
|
+
|
|
90
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
91
|
+
|
|
92
|
+
const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
|
|
93
|
+
setIsDragging(true);
|
|
94
|
+
e.dataTransfer.setDragImage(tableHeadCellRef.current as HTMLElement, 0, 0);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleDragEnd = (_e: DragEvent<HTMLButtonElement>) => {
|
|
98
|
+
setIsDragging(false);
|
|
99
|
+
setCurrentHoveredColumn(null);
|
|
100
|
+
if (currentHoveredColumn) {
|
|
101
|
+
setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const handleDragEnter = (_e: DragEvent) => {
|
|
106
|
+
setCurrentHoveredColumn(columnDefType === 'data' ? column : null);
|
|
107
|
+
};
|
|
108
|
+
|
|
83
109
|
return (
|
|
84
110
|
<TableCell
|
|
85
111
|
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
86
112
|
colSpan={header.colSpan}
|
|
113
|
+
onDragEnter={handleDragEnter}
|
|
114
|
+
ref={tableHeadCellRef}
|
|
87
115
|
{...tableCellProps}
|
|
88
|
-
ref={
|
|
89
|
-
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
90
|
-
}
|
|
91
116
|
sx={(theme: Theme) => ({
|
|
92
117
|
backgroundColor:
|
|
93
118
|
column.getIsPinned() && columnDefType !== 'group'
|
|
94
119
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
95
120
|
: 'inherit',
|
|
96
121
|
backgroundImage: 'inherit',
|
|
122
|
+
border: isDragging
|
|
123
|
+
? `2px dashed ${theme.palette.divider}`
|
|
124
|
+
: currentHoveredColumn?.id === column.id
|
|
125
|
+
? `2px dashed ${theme.palette.primary.main}`
|
|
126
|
+
: undefined,
|
|
97
127
|
boxShadow: getIsLastLeftPinnedColumn()
|
|
98
128
|
? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
99
129
|
: getIsFirstRightPinnedColumn()
|
|
100
130
|
? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
101
131
|
: undefined,
|
|
102
132
|
fontWeight: 'bold',
|
|
103
|
-
height: '100%',
|
|
104
133
|
left:
|
|
105
134
|
column.getIsPinned() === 'left'
|
|
106
135
|
? `${column.getStart('left')}px`
|
|
107
136
|
: undefined,
|
|
108
137
|
overflow: 'visible',
|
|
138
|
+
opacity: isDragging ? 0.5 : 1,
|
|
109
139
|
p:
|
|
110
140
|
density === 'compact'
|
|
111
141
|
? columnDefType === 'display'
|
|
@@ -124,7 +154,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
124
154
|
? 'sticky'
|
|
125
155
|
: undefined,
|
|
126
156
|
pt:
|
|
127
|
-
columnDefType
|
|
157
|
+
columnDefType === 'group'
|
|
128
158
|
? 0
|
|
129
159
|
: density === 'compact'
|
|
130
160
|
? '0.25'
|
|
@@ -135,8 +165,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
135
165
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
136
166
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
137
167
|
userSelect: enableMultiSort && column.getCanSort() ? 'none' : undefined,
|
|
138
|
-
verticalAlign:
|
|
139
|
-
columnDefType === 'display' && showFilters ? 'center' : 'text-top',
|
|
168
|
+
verticalAlign: 'text-top',
|
|
140
169
|
zIndex: column.getIsResizing()
|
|
141
170
|
? 3
|
|
142
171
|
: column.getIsPinned() && columnDefType !== 'group'
|
|
@@ -152,7 +181,6 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
152
181
|
headerElement
|
|
153
182
|
) : (
|
|
154
183
|
<Box
|
|
155
|
-
ref={previewRef}
|
|
156
184
|
sx={{
|
|
157
185
|
alignItems: 'flex-start',
|
|
158
186
|
display: 'flex',
|
|
@@ -191,7 +219,8 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
191
219
|
columnDef.enableColumnOrdering !== false) ||
|
|
192
220
|
(enableGrouping && columnDef.enableGrouping !== false)) && (
|
|
193
221
|
<MRT_GrabHandleButton
|
|
194
|
-
|
|
222
|
+
handleDragStart={handleDragStart}
|
|
223
|
+
handleDragEnd={handleDragEnd}
|
|
195
224
|
table={table}
|
|
196
225
|
/>
|
|
197
226
|
)}
|
|
@@ -14,11 +14,11 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
14
14
|
table,
|
|
15
15
|
}) => {
|
|
16
16
|
const { getState } = table;
|
|
17
|
-
const { currentFilterFns,
|
|
17
|
+
const { currentFilterFns, showColumnFilters } = getState();
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
|
-
<Collapse in={
|
|
21
|
+
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
22
22
|
{currentFilterFns[column.id] === 'between' ? (
|
|
23
23
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
24
24
|
) : (
|
|
@@ -12,7 +12,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
12
12
|
getState,
|
|
13
13
|
options: { columnResizeMode },
|
|
14
14
|
} = table;
|
|
15
|
-
const { density,
|
|
15
|
+
const { density, showColumnFilters } = getState();
|
|
16
16
|
const { column } = header;
|
|
17
17
|
const { columnDef } = column;
|
|
18
18
|
const { columnDefType } = columnDef;
|
|
@@ -26,7 +26,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
26
26
|
borderRadius: '2px',
|
|
27
27
|
borderRightWidth: '2px',
|
|
28
28
|
cursor: 'col-resize',
|
|
29
|
-
height:
|
|
29
|
+
height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
|
|
30
30
|
mr: density === 'compact' ? '-0.5rem' : '-1rem',
|
|
31
31
|
opacity: 0.8,
|
|
32
32
|
position: 'absolute',
|
|
@@ -1,17 +1,28 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
1
|
+
import React, { Dispatch, FC, SetStateAction } from 'react';
|
|
2
2
|
import { alpha, lighten, TableRow } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import type {
|
|
5
|
+
MRT_Column,
|
|
6
|
+
MRT_Header,
|
|
7
|
+
MRT_HeaderGroup,
|
|
8
|
+
MRT_TableInstance,
|
|
9
|
+
} from '..';
|
|
6
10
|
|
|
7
11
|
interface Props {
|
|
12
|
+
currentHoveredColumn: MRT_Column | null;
|
|
13
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
|
8
14
|
headerGroup: MRT_HeaderGroup;
|
|
9
15
|
table: MRT_TableInstance;
|
|
10
16
|
}
|
|
11
17
|
|
|
12
|
-
export const MRT_TableHeadRow: FC<Props> = ({
|
|
18
|
+
export const MRT_TableHeadRow: FC<Props> = ({
|
|
19
|
+
currentHoveredColumn,
|
|
20
|
+
setCurrentHoveredColumn,
|
|
21
|
+
headerGroup,
|
|
22
|
+
table,
|
|
23
|
+
}) => {
|
|
13
24
|
const {
|
|
14
|
-
options: {
|
|
25
|
+
options: { muiTableHeadRowProps },
|
|
15
26
|
} = table;
|
|
16
27
|
|
|
17
28
|
const tableRowProps =
|
|
@@ -28,21 +39,15 @@ export const MRT_TableHeadRow: FC<Props> = ({ headerGroup, table }) => {
|
|
|
28
39
|
...(tableRowProps?.sx as any),
|
|
29
40
|
})}
|
|
30
41
|
>
|
|
31
|
-
{headerGroup.headers.map((header: MRT_Header, index) =>
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
header={header}
|
|
41
|
-
key={header.id || index}
|
|
42
|
-
table={table}
|
|
43
|
-
/>
|
|
44
|
-
),
|
|
45
|
-
)}
|
|
42
|
+
{headerGroup.headers.map((header: MRT_Header, index) => (
|
|
43
|
+
<MRT_TableHeadCell
|
|
44
|
+
currentHoveredColumn={currentHoveredColumn}
|
|
45
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
46
|
+
header={header}
|
|
47
|
+
key={header.id || index}
|
|
48
|
+
table={table}
|
|
49
|
+
/>
|
|
50
|
+
))}
|
|
46
51
|
</TableRow>
|
|
47
52
|
);
|
|
48
53
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { FC, useMemo } from 'react';
|
|
1
|
+
import React, { FC, useMemo, useState } from 'react';
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
4
4
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
@@ -62,6 +62,9 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
62
62
|
getRightLeafColumns(),
|
|
63
63
|
]) as MRT_Column[];
|
|
64
64
|
|
|
65
|
+
const [currentHoveredColumn, setCurrentHoveredColumn] =
|
|
66
|
+
useState<MRT_Column | null>(null);
|
|
67
|
+
|
|
65
68
|
return (
|
|
66
69
|
<Menu
|
|
67
70
|
anchorEl={anchorEl}
|
|
@@ -118,8 +121,10 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
118
121
|
<MRT_ShowHideColumnsMenuItems
|
|
119
122
|
allColumns={allColumns}
|
|
120
123
|
column={column}
|
|
124
|
+
currentHoveredColumn={currentHoveredColumn}
|
|
121
125
|
isSubMenu={isSubMenu}
|
|
122
126
|
key={`${index}-${column.id}`}
|
|
127
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
123
128
|
table={table}
|
|
124
129
|
/>
|
|
125
130
|
))}
|