material-react-table 0.21.0 → 0.22.0
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/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/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 +177 -4409
- 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 +141 -136
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +3 -1
- package/package.json +1 -3
- 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_GrabHandleButton.tsx +12 -5
- package/src/head/MRT_TableHead.tsx +11 -3
- package/src/head/MRT_TableHeadCell.tsx +49 -20
- 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/table/MRT_Table.tsx +17 -4
- package/src/table/MRT_TableContainer.tsx +1 -1
- package/src/table/MRT_TablePaper.tsx +21 -25
- package/dist/head/MRT_DraggableTableHeadCell.d.ts +0 -8
- package/src/head/MRT_DraggableTableHeadCell.tsx +0 -43
@@ -1,9 +1,11 @@
|
|
1
|
-
import { FC } from 'react';
|
1
|
+
import { Dispatch, FC, SetStateAction } from 'react';
|
2
2
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
3
3
|
interface Props {
|
4
4
|
allColumns: MRT_Column[];
|
5
5
|
column: MRT_Column;
|
6
|
+
currentHoveredColumn: MRT_Column | null;
|
6
7
|
isSubMenu?: boolean;
|
8
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
7
9
|
table: MRT_TableInstance;
|
8
10
|
}
|
9
11
|
export declare const MRT_ShowHideColumnsMenuItems: FC<Props>;
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "0.
|
2
|
+
"version": "0.22.0",
|
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.",
|
@@ -99,8 +99,6 @@
|
|
99
99
|
"dependencies": {
|
100
100
|
"@tanstack/match-sorter-utils": "8.1.1",
|
101
101
|
"@tanstack/react-table": "8.1.3",
|
102
|
-
"react-dnd": "^16.0.1",
|
103
|
-
"react-dnd-html5-backend": "^16.0.1",
|
104
102
|
"react-virtual": "^2.10.4"
|
105
103
|
}
|
106
104
|
}
|
@@ -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
|
))}
|
@@ -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
|
+
};
|
@@ -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
|
)}
|
@@ -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
|
))}
|
@@ -1,5 +1,10 @@
|
|
1
|
-
import React, {
|
2
|
-
|
1
|
+
import React, {
|
2
|
+
Dispatch,
|
3
|
+
DragEvent,
|
4
|
+
FC,
|
5
|
+
SetStateAction,
|
6
|
+
useState,
|
7
|
+
} from 'react';
|
3
8
|
import {
|
4
9
|
Box,
|
5
10
|
FormControlLabel,
|
@@ -16,12 +21,16 @@ import type { MRT_Column, MRT_TableInstance } from '..';
|
|
16
21
|
interface Props {
|
17
22
|
allColumns: MRT_Column[];
|
18
23
|
column: MRT_Column;
|
24
|
+
currentHoveredColumn: MRT_Column | null;
|
19
25
|
isSubMenu?: boolean;
|
26
|
+
setCurrentHoveredColumn: Dispatch<SetStateAction<MRT_Column | null>>;
|
20
27
|
table: MRT_TableInstance;
|
21
28
|
}
|
22
29
|
|
23
30
|
export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
24
31
|
allColumns,
|
32
|
+
currentHoveredColumn,
|
33
|
+
setCurrentHoveredColumn,
|
25
34
|
column,
|
26
35
|
isSubMenu,
|
27
36
|
table,
|
@@ -40,22 +49,6 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
40
49
|
const { columnDef } = column;
|
41
50
|
const { columnDefType } = columnDef;
|
42
51
|
|
43
|
-
const [, dropRef] = useDrop({
|
44
|
-
accept: 'column',
|
45
|
-
drop: (movingColumn: MRT_Column) => {
|
46
|
-
const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
|
47
|
-
setColumnOrder(newColumnOrder);
|
48
|
-
},
|
49
|
-
});
|
50
|
-
|
51
|
-
const [, dragRef, previewRef] = useDrag({
|
52
|
-
collect: (monitor) => ({
|
53
|
-
isDragging: monitor.isDragging(),
|
54
|
-
}),
|
55
|
-
item: () => column,
|
56
|
-
type: 'column',
|
57
|
-
});
|
58
|
-
|
59
52
|
const switchChecked =
|
60
53
|
(columnDefType !== 'group' && column.getIsVisible()) ||
|
61
54
|
(columnDefType === 'group' &&
|
@@ -71,41 +64,73 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
71
64
|
}
|
72
65
|
};
|
73
66
|
|
67
|
+
const menuItemRef = React.useRef<HTMLElement>(null);
|
68
|
+
|
69
|
+
const [isDragging, setIsDragging] = useState(false);
|
70
|
+
|
71
|
+
const handleDragStart = (e: DragEvent<HTMLButtonElement>) => {
|
72
|
+
setIsDragging(true);
|
73
|
+
e.dataTransfer.setDragImage(menuItemRef.current as HTMLElement, 0, 0);
|
74
|
+
};
|
75
|
+
|
76
|
+
const handleDragEnd = (_e: DragEvent<HTMLButtonElement>) => {
|
77
|
+
setIsDragging(false);
|
78
|
+
setCurrentHoveredColumn(null);
|
79
|
+
if (currentHoveredColumn) {
|
80
|
+
setColumnOrder(reorderColumn(column, currentHoveredColumn, columnOrder));
|
81
|
+
}
|
82
|
+
};
|
83
|
+
|
84
|
+
const handleDragEnter = (_e: DragEvent) => {
|
85
|
+
if (!isDragging) {
|
86
|
+
setCurrentHoveredColumn(column);
|
87
|
+
}
|
88
|
+
};
|
89
|
+
|
74
90
|
return (
|
75
91
|
<>
|
76
92
|
<MenuItem
|
77
|
-
|
78
|
-
|
93
|
+
disableRipple={enableColumnOrdering}
|
94
|
+
ref={menuItemRef as any}
|
95
|
+
onDragEnter={handleDragEnter}
|
96
|
+
sx={(theme) => ({
|
79
97
|
alignItems: 'center',
|
80
98
|
justifyContent: 'flex-start',
|
81
99
|
my: 0,
|
100
|
+
opacity: isDragging ? 0.5 : 1,
|
101
|
+
outline: isDragging
|
102
|
+
? `1px dashed ${theme.palette.divider}`
|
103
|
+
: currentHoveredColumn?.id === column.id
|
104
|
+
? `2px dashed ${theme.palette.primary.main}`
|
105
|
+
: 'none',
|
82
106
|
pl: `${(column.depth + 0.5) * 2}rem`,
|
83
107
|
py: '6px',
|
84
|
-
}}
|
108
|
+
})}
|
85
109
|
>
|
86
110
|
<Box
|
87
|
-
ref={previewRef}
|
88
111
|
sx={{
|
89
112
|
display: 'flex',
|
90
113
|
flexWrap: 'nowrap',
|
91
114
|
gap: '8px',
|
92
115
|
}}
|
93
116
|
>
|
94
|
-
{
|
117
|
+
{!isSubMenu &&
|
118
|
+
columnDefType !== 'group' &&
|
95
119
|
enableColumnOrdering &&
|
96
120
|
!allColumns.some(
|
97
121
|
(col) => col.columnDef.columnDefType === 'group',
|
98
122
|
) &&
|
99
123
|
(columnDef.enableColumnOrdering !== false ? (
|
100
124
|
<MRT_GrabHandleButton
|
101
|
-
|
125
|
+
handleDragEnd={handleDragEnd}
|
126
|
+
handleDragStart={handleDragStart}
|
102
127
|
table={table}
|
103
128
|
/>
|
104
129
|
) : (
|
105
130
|
<Box sx={{ width: '28px' }} />
|
106
131
|
))}
|
107
|
-
{
|
108
|
-
|
132
|
+
{!isSubMenu &&
|
133
|
+
enablePinning &&
|
109
134
|
(column.getCanPin() ? (
|
110
135
|
<MRT_ColumnPinningButtons column={column} table={table} />
|
111
136
|
) : (
|
@@ -150,9 +175,11 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
150
175
|
{column.columns?.map((c: MRT_Column, i) => (
|
151
176
|
<MRT_ShowHideColumnsMenuItems
|
152
177
|
allColumns={allColumns}
|
153
|
-
key={`${i}-${c.id}`}
|
154
178
|
column={c}
|
179
|
+
currentHoveredColumn={currentHoveredColumn}
|
155
180
|
isSubMenu={isSubMenu}
|
181
|
+
key={`${i}-${c.id}`}
|
182
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
156
183
|
table={table}
|
157
184
|
/>
|
158
185
|
))}
|
package/src/table/MRT_Table.tsx
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
import React, { FC, RefObject } from 'react';
|
1
|
+
import React, { FC, RefObject, useState } from 'react';
|
2
2
|
import { Table } from '@mui/material';
|
3
3
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
4
4
|
import { MRT_TableBody } from '../body/MRT_TableBody';
|
5
5
|
import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
6
|
-
import { MRT_TableInstance } from '..';
|
6
|
+
import { MRT_Column, MRT_TableInstance } from '..';
|
7
7
|
|
8
8
|
interface Props {
|
9
9
|
tableContainerRef: RefObject<HTMLDivElement>;
|
@@ -29,6 +29,9 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, table }) => {
|
|
29
29
|
? muiTableProps({ table })
|
30
30
|
: muiTableProps;
|
31
31
|
|
32
|
+
const [currentHoveredColumn, setCurrentHoveredColumn] =
|
33
|
+
useState<MRT_Column | null>(null);
|
34
|
+
|
32
35
|
return (
|
33
36
|
<Table
|
34
37
|
stickyHeader={
|
@@ -41,8 +44,18 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, table }) => {
|
|
41
44
|
...tableProps?.sx,
|
42
45
|
}}
|
43
46
|
>
|
44
|
-
{enableTableHead &&
|
45
|
-
|
47
|
+
{enableTableHead && (
|
48
|
+
<MRT_TableHead
|
49
|
+
currentHoveredColumn={currentHoveredColumn}
|
50
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
51
|
+
table={table}
|
52
|
+
/>
|
53
|
+
)}
|
54
|
+
<MRT_TableBody
|
55
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
56
|
+
tableContainerRef={tableContainerRef}
|
57
|
+
table={table}
|
58
|
+
/>
|
46
59
|
{enableTableFooter && <MRT_TableFooter table={table} />}
|
47
60
|
</Table>
|
48
61
|
);
|