material-react-table 0.19.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 +187 -4412
- 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 +154 -142
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +3 -1
- package/package.json +2 -4
- package/src/body/MRT_TableBody.tsx +25 -12
- 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.",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@emotion/styled": "^11.9.3",
|
|
62
62
|
"@faker-js/faker": "^7.3.0",
|
|
63
63
|
"@mui/icons-material": "^5.8.4",
|
|
64
|
-
"@mui/material": "^5.8.
|
|
64
|
+
"@mui/material": "^5.8.7",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
66
|
"@storybook/addon-a11y": "^6.5.9",
|
|
67
67
|
"@storybook/addon-actions": "^6.5.9",
|
|
@@ -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
|
-
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
6
5
|
import { rankGlobalFuzzy } from '../sortingFns';
|
|
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,
|
|
@@ -62,19 +67,27 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
62
67
|
|
|
63
68
|
const rowVirtualizer = enableRowVirtualization
|
|
64
69
|
? useVirtual({
|
|
65
|
-
|
|
66
|
-
|
|
70
|
+
// estimateSize: () => (density === 'compact' ? 25 : 50),
|
|
71
|
+
overscan: density === 'compact' ? 30 : 10,
|
|
67
72
|
parentRef: tableContainerRef,
|
|
73
|
+
size: rows.length,
|
|
68
74
|
...virtualizerProps,
|
|
69
75
|
})
|
|
70
76
|
: ({} as any);
|
|
71
77
|
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
const virtualRows = enableRowVirtualization
|
|
79
|
+
? rowVirtualizer.virtualItems
|
|
80
|
+
: [];
|
|
81
|
+
|
|
82
|
+
let paddingTop = 0;
|
|
83
|
+
let paddingBottom = 0;
|
|
84
|
+
if (enableRowVirtualization) {
|
|
85
|
+
paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
|
|
86
|
+
paddingBottom =
|
|
87
|
+
virtualRows.length > 0
|
|
88
|
+
? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end
|
|
89
|
+
: 0;
|
|
90
|
+
}
|
|
78
91
|
|
|
79
92
|
return (
|
|
80
93
|
<TableBody {...tableBodyProps}>
|
|
@@ -83,7 +96,6 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
83
96
|
<td style={{ height: `${paddingTop}px` }} />
|
|
84
97
|
</tr>
|
|
85
98
|
)}
|
|
86
|
-
{/* @ts-ignore */}
|
|
87
99
|
{(enableRowVirtualization ? virtualRows : rows).map(
|
|
88
100
|
(rowOrVirtualRow: any, rowIndex: number) => {
|
|
89
101
|
const row = enableRowVirtualization
|
|
@@ -96,6 +108,7 @@ export const MRT_TableBody: FC<Props> = ({ table, tableContainerRef }) => {
|
|
|
96
108
|
rowIndex={
|
|
97
109
|
enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
|
|
98
110
|
}
|
|
111
|
+
setCurrentHoveredColumn={setCurrentHoveredColumn}
|
|
99
112
|
table={table}
|
|
100
113
|
/>
|
|
101
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
|
))}
|