material-react-table 0.7.5 → 0.7.6
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/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +91 -24
- 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 +92 -25
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/buttons/MRT_ColumnPinningButtons.tsx +69 -0
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -3
- package/src/table/MRT_Table.tsx +3 -3
- package/src/table/MRT_TableContainer.tsx +16 -6
- package/src/table/MRT_TableRoot.tsx +3 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.7.
|
|
2
|
+
"version": "0.7.6",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"@etchteam/storybook-addon-status": "^4.2.1",
|
|
62
62
|
"@faker-js/faker": "^6.2.0",
|
|
63
63
|
"@mui/icons-material": "^5.6.2",
|
|
64
|
-
"@mui/material": "^5.6.
|
|
64
|
+
"@mui/material": "^5.6.3",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
66
|
"@storybook/addon-a11y": "^6.4.22",
|
|
67
67
|
"@storybook/addon-actions": "^6.4.22",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/react-table": "^8.0.0-alpha.
|
|
100
|
+
"@tanstack/react-table": "^8.0.0-alpha.48",
|
|
101
101
|
"match-sorter": "^6.3.1"
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React, { FC } from 'react';
|
|
2
|
+
import { Box, IconButton, Tooltip } from '@mui/material';
|
|
3
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
column: MRT_Column;
|
|
7
|
+
tableInstance: MRT_TableInstance;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const MRT_ColumnPinningButtons: FC<Props> = ({
|
|
11
|
+
column,
|
|
12
|
+
tableInstance,
|
|
13
|
+
}) => {
|
|
14
|
+
const {
|
|
15
|
+
getState,
|
|
16
|
+
options: {
|
|
17
|
+
icons: { PushPinIcon },
|
|
18
|
+
localization,
|
|
19
|
+
},
|
|
20
|
+
} = tableInstance;
|
|
21
|
+
|
|
22
|
+
const { columnOrder } = getState();
|
|
23
|
+
|
|
24
|
+
const handlePinColumn = (pinDirection: 'left' | 'right' | false) => {
|
|
25
|
+
column.pin(pinDirection);
|
|
26
|
+
if (column.columnDefType === 'display') {
|
|
27
|
+
tableInstance.setColumnOrder([column.id, ...columnOrder]);
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const pinned = column.getIsPinned();
|
|
32
|
+
|
|
33
|
+
return (
|
|
34
|
+
<Box sx={{ mr: '8px' }}>
|
|
35
|
+
<Tooltip
|
|
36
|
+
arrow
|
|
37
|
+
title={pinned === 'left' ? localization.unpin : localization.pinToLeft}
|
|
38
|
+
>
|
|
39
|
+
<IconButton
|
|
40
|
+
onClick={() => handlePinColumn(pinned === 'left' ? false : 'left')}
|
|
41
|
+
size="small"
|
|
42
|
+
>
|
|
43
|
+
<PushPinIcon
|
|
44
|
+
style={{
|
|
45
|
+
transform: pinned === 'left' ? 'rotate(0)' : 'rotate(90deg)',
|
|
46
|
+
}}
|
|
47
|
+
/>
|
|
48
|
+
</IconButton>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
<Tooltip
|
|
51
|
+
arrow
|
|
52
|
+
title={
|
|
53
|
+
pinned === 'right' ? localization.unpin : localization.pinToRight
|
|
54
|
+
}
|
|
55
|
+
>
|
|
56
|
+
<IconButton
|
|
57
|
+
onClick={() => handlePinColumn(pinned === 'right' ? false : 'right')}
|
|
58
|
+
size="small"
|
|
59
|
+
>
|
|
60
|
+
<PushPinIcon
|
|
61
|
+
style={{
|
|
62
|
+
transform: pinned === 'right' ? 'rotate(0)' : 'rotate(-90deg)',
|
|
63
|
+
}}
|
|
64
|
+
/>
|
|
65
|
+
</IconButton>
|
|
66
|
+
</Tooltip>
|
|
67
|
+
</Box>
|
|
68
|
+
);
|
|
69
|
+
};
|
package/src/localization.ts
CHANGED
|
@@ -56,6 +56,7 @@ export interface MRT_Localization {
|
|
|
56
56
|
toggleSelectRow: string;
|
|
57
57
|
ungroupByColumn: string;
|
|
58
58
|
unpin: string;
|
|
59
|
+
unpinAll: string;
|
|
59
60
|
unsorted: string;
|
|
60
61
|
}
|
|
61
62
|
|
|
@@ -118,5 +119,6 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
118
119
|
toggleSelectRow: 'Toggle select row',
|
|
119
120
|
ungroupByColumn: 'Ungroup by {column}',
|
|
120
121
|
unpin: 'Unpin',
|
|
122
|
+
unpinAll: 'Unpin all',
|
|
121
123
|
unsorted: 'Unsorted',
|
|
122
124
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC, useMemo } from 'react';
|
|
2
2
|
import { Button, Menu, Divider, Box } from '@mui/material';
|
|
3
3
|
import { MRT_ShowHideColumnsMenuItems } from './MRT_ShowHideColumnsMenuItems';
|
|
4
|
-
import { MRT_TableInstance } from '..';
|
|
4
|
+
import { MRT_Column, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
anchorEl: HTMLElement | null;
|
|
@@ -24,7 +24,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
24
24
|
getState,
|
|
25
25
|
toggleAllColumnsVisible,
|
|
26
26
|
getAllLeafColumns,
|
|
27
|
-
options: { localization },
|
|
27
|
+
options: { localization, enablePinning },
|
|
28
28
|
} = tableInstance;
|
|
29
29
|
|
|
30
30
|
const { isDensePadding } = getState();
|
|
@@ -40,14 +40,16 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
40
40
|
[getAllColumns()],
|
|
41
41
|
);
|
|
42
42
|
|
|
43
|
-
const allDataColumns = useMemo(() => {
|
|
43
|
+
const allDataColumns: (MRT_Column | null)[] = useMemo(() => {
|
|
44
44
|
const dataColumns = getAllColumns().filter(
|
|
45
45
|
(col) => col.columnDefType !== 'display',
|
|
46
46
|
);
|
|
47
47
|
return getIsSomeColumnsPinned()
|
|
48
48
|
? [
|
|
49
49
|
...dataColumns.filter((c) => c.getIsPinned() === 'left'),
|
|
50
|
+
null,
|
|
50
51
|
...dataColumns.filter((c) => c.getIsPinned() === false),
|
|
52
|
+
null,
|
|
51
53
|
...dataColumns.filter((c) => c.getIsPinned() === 'right'),
|
|
52
54
|
]
|
|
53
55
|
: dataColumns;
|
|
@@ -78,6 +80,14 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
78
80
|
{localization.hideAll}
|
|
79
81
|
</Button>
|
|
80
82
|
)}
|
|
83
|
+
{!isSubMenu && enablePinning && (
|
|
84
|
+
<Button
|
|
85
|
+
disabled={!getIsSomeColumnsPinned()}
|
|
86
|
+
onClick={() => tableInstance.setColumnPinning({})}
|
|
87
|
+
>
|
|
88
|
+
{localization.unpinAll}
|
|
89
|
+
</Button>
|
|
90
|
+
)}
|
|
81
91
|
<Button
|
|
82
92
|
disabled={getIsAllColumnsVisible()}
|
|
83
93
|
onClick={() => toggleAllColumnsVisible(true)}
|
|
@@ -95,14 +105,18 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
95
105
|
/>
|
|
96
106
|
))}
|
|
97
107
|
<Divider />
|
|
98
|
-
{allDataColumns.map((column, index) =>
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
{allDataColumns.map((column, index) =>
|
|
109
|
+
column ? (
|
|
110
|
+
<MRT_ShowHideColumnsMenuItems
|
|
111
|
+
column={column}
|
|
112
|
+
isSubMenu={isSubMenu}
|
|
113
|
+
key={`${index}-${column.id}`}
|
|
114
|
+
tableInstance={tableInstance}
|
|
115
|
+
/>
|
|
116
|
+
) : (
|
|
117
|
+
<Divider key={`${index}-divider`} />
|
|
118
|
+
),
|
|
119
|
+
)}
|
|
106
120
|
</Menu>
|
|
107
121
|
);
|
|
108
122
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
3
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
4
|
-
import {
|
|
4
|
+
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
column: MRT_Column;
|
|
@@ -16,7 +16,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
16
16
|
}) => {
|
|
17
17
|
const {
|
|
18
18
|
getState,
|
|
19
|
-
options: { onToggleColumnVisibility },
|
|
19
|
+
options: { onToggleColumnVisibility, enablePinning },
|
|
20
20
|
} = tableInstance;
|
|
21
21
|
|
|
22
22
|
const { columnVisibility } = getState();
|
|
@@ -44,8 +44,20 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
44
44
|
return (
|
|
45
45
|
<>
|
|
46
46
|
<MenuItem
|
|
47
|
-
sx={{
|
|
47
|
+
sx={{
|
|
48
|
+
alignItems: 'center',
|
|
49
|
+
justifyContent: 'flex-start',
|
|
50
|
+
my: 0,
|
|
51
|
+
pl: `${(column.depth + 0.5) * 2}rem`,
|
|
52
|
+
py: '6px',
|
|
53
|
+
}}
|
|
48
54
|
>
|
|
55
|
+
{!isSubMenu && enablePinning && (
|
|
56
|
+
<MRT_ColumnPinningButtons
|
|
57
|
+
column={column}
|
|
58
|
+
tableInstance={tableInstance}
|
|
59
|
+
/>
|
|
60
|
+
)}
|
|
49
61
|
<FormControlLabel
|
|
50
62
|
componentsProps={{ typography: { sx: { marginBottom: 0 } } }}
|
|
51
63
|
checked={switchChecked}
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -14,10 +14,10 @@ export const MRT_Table: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
14
14
|
const {
|
|
15
15
|
getTableProps,
|
|
16
16
|
options: {
|
|
17
|
-
muiTableProps,
|
|
18
|
-
enableTableHead,
|
|
19
|
-
enableTableFooter,
|
|
20
17
|
enableStickyHeader,
|
|
18
|
+
enableTableFooter,
|
|
19
|
+
enableTableHead,
|
|
20
|
+
muiTableProps,
|
|
21
21
|
},
|
|
22
22
|
} = tableInstance;
|
|
23
23
|
|
|
@@ -30,7 +30,6 @@ interface Props {
|
|
|
30
30
|
export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
31
31
|
const {
|
|
32
32
|
getCenterTableWidth,
|
|
33
|
-
getIsSomeColumnsPinned,
|
|
34
33
|
getLeftTableWidth,
|
|
35
34
|
getRightTableWidth,
|
|
36
35
|
getState,
|
|
@@ -42,7 +41,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
42
41
|
},
|
|
43
42
|
} = tableInstance;
|
|
44
43
|
|
|
45
|
-
const { isFullScreen
|
|
44
|
+
const { isFullScreen } = getState();
|
|
46
45
|
|
|
47
46
|
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
|
48
47
|
|
|
@@ -67,6 +66,9 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
67
66
|
setTotalToolbarHeight(topToolbarHeight + bottomToolbarHeight);
|
|
68
67
|
});
|
|
69
68
|
|
|
69
|
+
const isSomeColumnsPinnedLeft = !!tableInstance.getLeftFlatHeaders().length;
|
|
70
|
+
const isSomeColumnsPinnedRight = !!tableInstance.getRightFlatHeaders().length;
|
|
71
|
+
|
|
70
72
|
return (
|
|
71
73
|
<TableContainer
|
|
72
74
|
{...tableContainerProps}
|
|
@@ -84,7 +86,8 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
84
86
|
: undefined,
|
|
85
87
|
}}
|
|
86
88
|
>
|
|
87
|
-
{enablePinning &&
|
|
89
|
+
{(enablePinning && isSomeColumnsPinnedLeft) ||
|
|
90
|
+
isSomeColumnsPinnedRight ? (
|
|
88
91
|
<Box
|
|
89
92
|
sx={{
|
|
90
93
|
display: 'grid',
|
|
@@ -96,13 +99,20 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
96
99
|
commonBoxStyles({
|
|
97
100
|
pinned: 'left',
|
|
98
101
|
theme,
|
|
99
|
-
visible:
|
|
102
|
+
visible: isSomeColumnsPinnedLeft,
|
|
100
103
|
})
|
|
101
104
|
}
|
|
102
105
|
>
|
|
103
106
|
<MRT_Table pinned="left" tableInstance={tableInstance} />
|
|
104
107
|
</Box>
|
|
105
|
-
<Box
|
|
108
|
+
<Box
|
|
109
|
+
sx={(theme: Theme) =>
|
|
110
|
+
commonBoxStyles({
|
|
111
|
+
theme,
|
|
112
|
+
visible: !!tableInstance.getCenterFlatHeaders().length,
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
>
|
|
106
116
|
<MRT_Table pinned="center" tableInstance={tableInstance} />
|
|
107
117
|
</Box>
|
|
108
118
|
<Box
|
|
@@ -110,7 +120,7 @@ export const MRT_TableContainer: FC<Props> = ({ tableInstance }) => {
|
|
|
110
120
|
commonBoxStyles({
|
|
111
121
|
pinned: 'right',
|
|
112
122
|
theme,
|
|
113
|
-
visible:
|
|
123
|
+
visible: isSomeColumnsPinnedRight,
|
|
114
124
|
})
|
|
115
125
|
}
|
|
116
126
|
>
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
|
2
2
|
import {
|
|
3
|
+
ColumnDef,
|
|
4
|
+
FilterFn,
|
|
3
5
|
PaginationState,
|
|
4
6
|
Table,
|
|
5
7
|
createTable,
|
|
6
8
|
functionalUpdate,
|
|
7
9
|
getColumnFilteredRowModelSync,
|
|
10
|
+
getCoreRowModelSync,
|
|
8
11
|
getExpandedRowModel,
|
|
9
12
|
getGlobalFilteredRowModelSync,
|
|
10
13
|
getGroupedRowModelSync,
|
|
11
14
|
getPaginationRowModel,
|
|
12
15
|
getSortedRowModelSync,
|
|
13
16
|
useTableInstance,
|
|
14
|
-
getCoreRowModelSync,
|
|
15
|
-
ColumnDef,
|
|
16
|
-
FilterFn,
|
|
17
17
|
} from '@tanstack/react-table';
|
|
18
18
|
import {
|
|
19
19
|
MRT_Cell,
|