material-react-table 0.8.10 → 0.8.13
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/MaterialReactTable.d.ts +5 -4
- package/dist/buttons/MRT_GrabHandleButton.d.ts +8 -0
- package/dist/localization.d.ts +1 -0
- package/dist/material-react-table.cjs.development.js +1879 -1835
- 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 +202 -158
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -0
- package/dist/table/MRT_TableRoot.d.ts +0 -1
- package/dist/utils.d.ts +1 -1
- package/package.json +13 -13
- package/src/MaterialReactTable.tsx +5 -6
- package/src/body/MRT_TableBodyCell.tsx +8 -9
- package/src/buttons/MRT_ColumnPinningButtons.tsx +1 -1
- package/src/buttons/MRT_CopyButton.tsx +7 -3
- package/src/{head/MRT_TableHeadCellGrabHandle.tsx → buttons/MRT_GrabHandleButton.tsx} +2 -3
- package/src/buttons/MRT_ToggleColumnActionMenuButton.tsx +5 -4
- package/src/footer/MRT_TableFooterCell.tsx +2 -2
- package/src/footer/MRT_TableFooterRow.tsx +4 -4
- package/src/head/MRT_DraggableTableHeadCell.tsx +15 -9
- package/src/head/MRT_TableHeadCell.tsx +6 -12
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +3 -1
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +3 -2
- package/src/head/MRT_TableHeadCellSortLabel.tsx +4 -8
- package/src/inputs/MRT_FilterTextField.tsx +1 -1
- package/src/localization.ts +2 -0
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -38
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +74 -21
- package/src/table/MRT_TableRoot.tsx +29 -28
- package/dist/head/MRT_TableHeadCellGrabHandle.d.ts +0 -9
package/dist/utils.d.ts
CHANGED
|
@@ -7,6 +7,6 @@ export declare const createGroup: <D extends Record<string, any> = {}>(table: Ta
|
|
|
7
7
|
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
8
|
[key: string]: MRT_FilterFn<{}>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFN" | "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.13",
|
|
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.",
|
|
@@ -48,11 +48,11 @@
|
|
|
48
48
|
"size-limit": [
|
|
49
49
|
{
|
|
50
50
|
"path": "dist/material-react-table.cjs.production.min.js",
|
|
51
|
-
"limit": "
|
|
51
|
+
"limit": "50 KB"
|
|
52
52
|
},
|
|
53
53
|
{
|
|
54
54
|
"path": "dist/material-react-table.esm.js",
|
|
55
|
-
"limit": "
|
|
55
|
+
"limit": "50 KB"
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
58
|
"devDependencies": {
|
|
@@ -63,17 +63,17 @@
|
|
|
63
63
|
"@mui/icons-material": "^5.8.2",
|
|
64
64
|
"@mui/material": "^5.8.2",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
|
-
"@storybook/addon-a11y": "^6.5.
|
|
67
|
-
"@storybook/addon-actions": "^6.5.
|
|
68
|
-
"@storybook/addon-essentials": "^6.5.
|
|
66
|
+
"@storybook/addon-a11y": "^6.5.6",
|
|
67
|
+
"@storybook/addon-actions": "^6.5.6",
|
|
68
|
+
"@storybook/addon-essentials": "^6.5.6",
|
|
69
69
|
"@storybook/addon-info": "^5.3.21",
|
|
70
|
-
"@storybook/addon-links": "^6.5.
|
|
71
|
-
"@storybook/addons": "^6.5.
|
|
72
|
-
"@storybook/react": "^6.5.
|
|
73
|
-
"@types/react": "^18.0.
|
|
70
|
+
"@storybook/addon-links": "^6.5.6",
|
|
71
|
+
"@storybook/addons": "^6.5.6",
|
|
72
|
+
"@storybook/react": "^6.5.6",
|
|
73
|
+
"@types/react": "^18.0.11",
|
|
74
74
|
"@types/react-dom": "^18.0.5",
|
|
75
75
|
"babel-loader": "^8.2.5",
|
|
76
|
-
"eslint": "^8.
|
|
76
|
+
"eslint": "^8.17.0",
|
|
77
77
|
"eslint-plugin-react-hooks": "^4.5.0",
|
|
78
78
|
"husky": "^8.0.1",
|
|
79
79
|
"prettier": "^2.6.2",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"storybook-dark-mode": "^1.1.0",
|
|
88
88
|
"tsdx": "^0.14.1",
|
|
89
89
|
"tslib": "^2.4.0",
|
|
90
|
-
"typescript": "^4.7.
|
|
90
|
+
"typescript": "^4.7.3"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@emotion/react": ">=11",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
100
|
"@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
|
|
101
|
-
"@tanstack/react-table": "^8.0.0-
|
|
101
|
+
"@tanstack/react-table": "^8.0.0-beta.4",
|
|
102
102
|
"react-dnd": "^16.0.1",
|
|
103
103
|
"react-dnd-html5-backend": "^16.0.1"
|
|
104
104
|
}
|
|
@@ -35,7 +35,6 @@ import {
|
|
|
35
35
|
Header,
|
|
36
36
|
HeaderGroup,
|
|
37
37
|
Overwrite,
|
|
38
|
-
PaginationState,
|
|
39
38
|
ReactTableGenerics,
|
|
40
39
|
Row,
|
|
41
40
|
TableGenerics,
|
|
@@ -79,9 +78,11 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
79
78
|
>
|
|
80
79
|
>,
|
|
81
80
|
| 'getAllColumns'
|
|
81
|
+
| 'getAllFlatColumns'
|
|
82
82
|
| 'getAllLeafColumns'
|
|
83
83
|
| 'getColumn'
|
|
84
84
|
| 'getExpandedRowModel'
|
|
85
|
+
| 'getFlatHeaders'
|
|
85
86
|
| 'getPaginationRowModel'
|
|
86
87
|
| 'getPrePaginationRowModel'
|
|
87
88
|
| 'getRowModel'
|
|
@@ -90,9 +91,11 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
90
91
|
| 'options'
|
|
91
92
|
> & {
|
|
92
93
|
getAllColumns: () => MRT_Column<D>[];
|
|
94
|
+
getAllFlatColumns: () => MRT_Column<D>[];
|
|
93
95
|
getAllLeafColumns: () => MRT_Column<D>[];
|
|
94
96
|
getColumn: (columnId: string) => MRT_Column<D>;
|
|
95
97
|
getExpandedRowModel: () => MRT_RowModel<D>;
|
|
98
|
+
getFlatHeaders: () => MRT_Header<D>[];
|
|
96
99
|
getPaginationRowModel: () => MRT_RowModel<D>;
|
|
97
100
|
getPrePaginationRowModel: () => MRT_RowModel<D>;
|
|
98
101
|
getRowModel: () => MRT_RowModel<D>;
|
|
@@ -117,10 +120,7 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
117
120
|
setShowGlobalFilter: Dispatch<SetStateAction<boolean>>;
|
|
118
121
|
};
|
|
119
122
|
|
|
120
|
-
export type MRT_TableState<D extends Record<string, any> = {}> =
|
|
121
|
-
TableState,
|
|
122
|
-
'pagination'
|
|
123
|
-
> & {
|
|
123
|
+
export type MRT_TableState<D extends Record<string, any> = {}> = TableState & {
|
|
124
124
|
currentEditingCell: MRT_Cell<D> | null;
|
|
125
125
|
currentEditingRow: MRT_Row<D> | null;
|
|
126
126
|
currentFilterFns: Record<string, string | Function>;
|
|
@@ -128,7 +128,6 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
|
|
|
128
128
|
isDensePadding: boolean;
|
|
129
129
|
isLoading: boolean;
|
|
130
130
|
isFullScreen: boolean;
|
|
131
|
-
pagination: Partial<PaginationState>;
|
|
132
131
|
showFilters: boolean;
|
|
133
132
|
showGlobalFilter: boolean;
|
|
134
133
|
showProgressBars: boolean;
|
|
@@ -39,7 +39,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
39
39
|
|
|
40
40
|
const { column, row } = cell;
|
|
41
41
|
|
|
42
|
-
const { columnDef } = column;
|
|
42
|
+
const { columnDef, columnDefType } = column;
|
|
43
43
|
|
|
44
44
|
const mTableCellBodyProps =
|
|
45
45
|
muiTableBodyCellProps instanceof Function
|
|
@@ -58,11 +58,11 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
58
58
|
|
|
59
59
|
const skeletonWidth = useMemo(
|
|
60
60
|
() =>
|
|
61
|
-
|
|
61
|
+
columnDefType === 'display'
|
|
62
62
|
? column.getSize() / 2
|
|
63
63
|
: Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
64
64
|
column.getSize() / 3,
|
|
65
|
-
[
|
|
65
|
+
[columnDefType, column.getSize()],
|
|
66
66
|
);
|
|
67
67
|
|
|
68
68
|
const isEditable =
|
|
@@ -136,10 +136,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
136
136
|
? `${column.getStart('left')}px`
|
|
137
137
|
: undefined,
|
|
138
138
|
p: isDensePadding
|
|
139
|
-
?
|
|
139
|
+
? columnDefType === 'display'
|
|
140
140
|
? '0 0.5rem'
|
|
141
141
|
: '0.5rem'
|
|
142
|
-
:
|
|
142
|
+
: columnDefType === 'display'
|
|
143
143
|
? '0.5rem 0.75rem'
|
|
144
144
|
: '1rem',
|
|
145
145
|
pl:
|
|
@@ -175,7 +175,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
175
175
|
width={skeletonWidth}
|
|
176
176
|
{...muiTableBodyCellSkeletonProps}
|
|
177
177
|
/>
|
|
178
|
-
) :
|
|
178
|
+
) : columnDefType === 'display' ? (
|
|
179
179
|
columnDef.Cell?.({ cell, tableInstance })
|
|
180
180
|
) : cell.getIsPlaceholder() ||
|
|
181
181
|
(row.getIsGrouped() &&
|
|
@@ -189,7 +189,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
189
189
|
<>
|
|
190
190
|
<MRT_CopyButton cell={cell} tableInstance={tableInstance}>
|
|
191
191
|
<>
|
|
192
|
-
{
|
|
192
|
+
{columnDef?.Cell?.({ cell, tableInstance }) ??
|
|
193
193
|
cell.renderCell()}
|
|
194
194
|
</>
|
|
195
195
|
</MRT_CopyButton>
|
|
@@ -197,8 +197,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
197
197
|
</>
|
|
198
198
|
) : (
|
|
199
199
|
<>
|
|
200
|
-
{
|
|
201
|
-
cell.renderCell()}
|
|
200
|
+
{columnDef?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
|
|
202
201
|
{row.getIsGrouped() && <> ({row.subRows?.length ?? ''})</>}
|
|
203
202
|
</>
|
|
204
203
|
)}
|
|
@@ -23,7 +23,7 @@ export const MRT_ColumnPinningButtons: FC<Props> = ({
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
|
-
<Box sx={{ mr: '
|
|
26
|
+
<Box sx={{ mr: '4px' }}>
|
|
27
27
|
{column.getIsPinned() ? (
|
|
28
28
|
<Tooltip arrow title={localization.unpin}>
|
|
29
29
|
<IconButton onClick={() => handlePinColumn(false)} size="small">
|
|
@@ -17,6 +17,10 @@ export const MRT_CopyButton: FC<Props> = ({
|
|
|
17
17
|
options: { localization, muiTableBodyCellCopyButtonProps },
|
|
18
18
|
} = tableInstance;
|
|
19
19
|
|
|
20
|
+
const { column } = cell;
|
|
21
|
+
|
|
22
|
+
const { columnDef } = column;
|
|
23
|
+
|
|
20
24
|
const [copied, setCopied] = useState(false);
|
|
21
25
|
|
|
22
26
|
const handleCopy = (text: unknown) => {
|
|
@@ -31,12 +35,12 @@ export const MRT_CopyButton: FC<Props> = ({
|
|
|
31
35
|
: muiTableBodyCellCopyButtonProps;
|
|
32
36
|
|
|
33
37
|
const mcTableBodyCellCopyButtonProps =
|
|
34
|
-
|
|
35
|
-
?
|
|
38
|
+
columnDef.muiTableBodyCellCopyButtonProps instanceof Function
|
|
39
|
+
? columnDef.muiTableBodyCellCopyButtonProps({
|
|
36
40
|
cell,
|
|
37
41
|
tableInstance,
|
|
38
42
|
})
|
|
39
|
-
:
|
|
43
|
+
: columnDef.muiTableBodyCellCopyButtonProps;
|
|
40
44
|
|
|
41
45
|
const buttonProps = {
|
|
42
46
|
...mTableBodyCellCopyButtonProps,
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { IconButton, Tooltip } from '@mui/material';
|
|
2
2
|
import React, { FC, forwardRef, Ref } from 'react';
|
|
3
|
-
import {
|
|
3
|
+
import { MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
header: MRT_Header;
|
|
7
6
|
ref: Ref<HTMLButtonElement>;
|
|
8
7
|
tableInstance: MRT_TableInstance;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
export const
|
|
10
|
+
export const MRT_GrabHandleButton: FC<Props> = forwardRef(
|
|
12
11
|
({ tableInstance }, ref) => {
|
|
13
12
|
const {
|
|
14
13
|
options: {
|
|
@@ -22,6 +22,8 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
|
|
|
22
22
|
|
|
23
23
|
const { column } = header;
|
|
24
24
|
|
|
25
|
+
const { columnDef } = column;
|
|
26
|
+
|
|
25
27
|
const [anchorEl, setAnchorEl] = useState<null | HTMLElement>(null);
|
|
26
28
|
|
|
27
29
|
const handleClick = (event: MouseEvent<HTMLElement>) => {
|
|
@@ -36,13 +38,12 @@ export const MRT_ToggleColumnActionMenuButton: FC<Props> = ({
|
|
|
36
38
|
: muiTableHeadCellColumnActionsButtonProps;
|
|
37
39
|
|
|
38
40
|
const mcTableHeadCellColumnActionsButtonProps =
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
? column.columnDef.muiTableHeadCellColumnActionsButtonProps({
|
|
41
|
+
columnDef.muiTableHeadCellColumnActionsButtonProps instanceof Function
|
|
42
|
+
? columnDef.muiTableHeadCellColumnActionsButtonProps({
|
|
42
43
|
column,
|
|
43
44
|
tableInstance,
|
|
44
45
|
})
|
|
45
|
-
:
|
|
46
|
+
: columnDef.muiTableHeadCellColumnActionsButtonProps;
|
|
46
47
|
|
|
47
48
|
const iconButtonProps = {
|
|
48
49
|
...mTableHeadCellColumnActionsButtonProps,
|
|
@@ -17,7 +17,7 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
17
17
|
|
|
18
18
|
const { column } = footer;
|
|
19
19
|
|
|
20
|
-
const { columnDef } = column;
|
|
20
|
+
const { columnDef, columnDefType } = column;
|
|
21
21
|
|
|
22
22
|
const mTableFooterCellProps =
|
|
23
23
|
muiTableFooterCellProps instanceof Function
|
|
@@ -36,7 +36,7 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
36
36
|
|
|
37
37
|
return (
|
|
38
38
|
<TableCell
|
|
39
|
-
align={
|
|
39
|
+
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
40
40
|
colSpan={footer.colSpan}
|
|
41
41
|
variant="head"
|
|
42
42
|
{...tableCellProps}
|
|
@@ -19,10 +19,10 @@ export const MRT_TableFooterRow: FC<Props> = ({
|
|
|
19
19
|
// if no content in row, skip row
|
|
20
20
|
if (
|
|
21
21
|
!footerGroup.headers?.some(
|
|
22
|
-
(
|
|
23
|
-
(typeof
|
|
24
|
-
!!
|
|
25
|
-
|
|
22
|
+
(header) =>
|
|
23
|
+
(typeof header.column.columnDef.footer === 'string' &&
|
|
24
|
+
!!header.column.columnDef.footer) ||
|
|
25
|
+
header.column.columnDef.Footer,
|
|
26
26
|
)
|
|
27
27
|
)
|
|
28
28
|
return null;
|
|
@@ -20,18 +20,24 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({
|
|
|
20
20
|
|
|
21
21
|
const { columnOrder } = getState();
|
|
22
22
|
|
|
23
|
-
const reorder = (
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const reorder = (movingHeader: MRT_Header, receivingHeader: MRT_Header) => {
|
|
24
|
+
if (movingHeader.column.getCanPin()) {
|
|
25
|
+
movingHeader.column.pin(receivingHeader.column.getIsPinned());
|
|
26
|
+
}
|
|
27
|
+
columnOrder.splice(
|
|
28
|
+
receivingHeader.index,
|
|
29
|
+
0,
|
|
30
|
+
columnOrder.splice(movingHeader.index, 1)[0],
|
|
31
|
+
);
|
|
26
32
|
setColumnOrder([...columnOrder]);
|
|
27
33
|
};
|
|
28
34
|
|
|
29
|
-
const [,
|
|
35
|
+
const [, dropRef] = useDrop({
|
|
30
36
|
accept: 'header',
|
|
31
|
-
drop: (
|
|
37
|
+
drop: (movingHeader: MRT_Header) => reorder(movingHeader, header),
|
|
32
38
|
});
|
|
33
39
|
|
|
34
|
-
const [{ isDragging },
|
|
40
|
+
const [{ isDragging }, dragRef, previewRef] = useDrag({
|
|
35
41
|
collect: (monitor) => ({
|
|
36
42
|
isDragging: monitor.isDragging(),
|
|
37
43
|
}),
|
|
@@ -41,11 +47,11 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({
|
|
|
41
47
|
|
|
42
48
|
return (
|
|
43
49
|
<MRT_TableHeadCell
|
|
44
|
-
dragRef={
|
|
45
|
-
dropRef={
|
|
50
|
+
dragRef={dragRef}
|
|
51
|
+
dropRef={dropRef}
|
|
46
52
|
header={header}
|
|
47
53
|
isDragging={isDragging}
|
|
48
|
-
previewRef={
|
|
54
|
+
previewRef={previewRef}
|
|
49
55
|
tableInstance={tableInstance}
|
|
50
56
|
/>
|
|
51
57
|
);
|
|
@@ -2,7 +2,7 @@ import React, { FC, ReactNode, Ref } from 'react';
|
|
|
2
2
|
import { Box, TableCell, Theme, alpha, lighten } from '@mui/material';
|
|
3
3
|
import { MRT_TableHeadCellFilterContainer } from './MRT_TableHeadCellFilterContainer';
|
|
4
4
|
import { MRT_TableHeadCellFilterLabel } from './MRT_TableHeadCellFilterLabel';
|
|
5
|
-
import {
|
|
5
|
+
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
6
6
|
import { MRT_TableHeadCellResizeHandle } from './MRT_TableHeadCellResizeHandle';
|
|
7
7
|
import { MRT_TableHeadCellSortLabel } from './MRT_TableHeadCellSortLabel';
|
|
8
8
|
import { MRT_ToggleColumnActionMenuButton } from '../buttons/MRT_ToggleColumnActionMenuButton';
|
|
@@ -59,12 +59,12 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
const headerElement = (
|
|
62
|
-
|
|
63
|
-
?
|
|
62
|
+
columnDef?.Header instanceof Function
|
|
63
|
+
? columnDef?.Header?.({
|
|
64
64
|
header,
|
|
65
65
|
tableInstance,
|
|
66
66
|
})
|
|
67
|
-
:
|
|
67
|
+
: columnDef?.Header ?? header.renderHeader()
|
|
68
68
|
) as ReactNode;
|
|
69
69
|
|
|
70
70
|
const getIsLastLeftPinnedColumn = () => {
|
|
@@ -123,12 +123,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
123
123
|
column.getIsPinned() && columnDefType !== 'group'
|
|
124
124
|
? 'sticky'
|
|
125
125
|
: undefined,
|
|
126
|
-
pt:
|
|
127
|
-
columnDefType === 'display'
|
|
128
|
-
? 0
|
|
129
|
-
: isDensePadding
|
|
130
|
-
? '0.75rem'
|
|
131
|
-
: '1.25rem',
|
|
126
|
+
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.5rem',
|
|
132
127
|
right:
|
|
133
128
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
134
129
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
@@ -195,8 +190,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
195
190
|
((enableColumnOrdering &&
|
|
196
191
|
columnDef.enableColumnOrdering !== false) ||
|
|
197
192
|
(enableGrouping && columnDef.enableGrouping !== false)) && (
|
|
198
|
-
<
|
|
199
|
-
header={header}
|
|
193
|
+
<MRT_GrabHandleButton
|
|
200
194
|
ref={dragRef as Ref<HTMLButtonElement>}
|
|
201
195
|
tableInstance={tableInstance}
|
|
202
196
|
/>
|
|
@@ -24,11 +24,13 @@ export const MRT_TableHeadCellFilterLabel: FC<Props> = ({
|
|
|
24
24
|
|
|
25
25
|
const { column } = header;
|
|
26
26
|
|
|
27
|
+
const { columnDef } = column;
|
|
28
|
+
|
|
27
29
|
const filterFn = getState()?.currentFilterFns?.[header.id];
|
|
28
30
|
|
|
29
31
|
const filterTooltip = !!column.getFilterValue()
|
|
30
32
|
? localization.filteringByColumn
|
|
31
|
-
.replace('{column}', String(
|
|
33
|
+
.replace('{column}', String(columnDef.header))
|
|
32
34
|
.replace(
|
|
33
35
|
'{filterType}',
|
|
34
36
|
filterFn instanceof Function
|
|
@@ -17,6 +17,8 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
|
17
17
|
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
|
+
const { columnDefType } = column;
|
|
21
|
+
|
|
20
22
|
return (
|
|
21
23
|
<Divider
|
|
22
24
|
flexItem
|
|
@@ -26,8 +28,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
|
26
28
|
borderRadius: '2px',
|
|
27
29
|
borderRightWidth: '2px',
|
|
28
30
|
cursor: 'col-resize',
|
|
29
|
-
height:
|
|
30
|
-
showFilters && column.columnDefType === 'data' ? '4rem' : '2rem',
|
|
31
|
+
height: showFilters && columnDefType === 'data' ? '4rem' : '2rem',
|
|
31
32
|
opacity: 0.8,
|
|
32
33
|
position: 'absolute',
|
|
33
34
|
right: '1px',
|
|
@@ -17,16 +17,12 @@ export const MRT_TableHeadCellSortLabel: FC<Props> = ({
|
|
|
17
17
|
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
|
+
const { columnDef } = column;
|
|
21
|
+
|
|
20
22
|
const sortTooltip = !!column.getIsSorted()
|
|
21
23
|
? column.getIsSorted() === 'desc'
|
|
22
|
-
? localization.sortedByColumnDesc.replace(
|
|
23
|
-
|
|
24
|
-
column.columnDef.header,
|
|
25
|
-
)
|
|
26
|
-
: localization.sortedByColumnAsc.replace(
|
|
27
|
-
'{column}',
|
|
28
|
-
column.columnDef.header,
|
|
29
|
-
)
|
|
24
|
+
? localization.sortedByColumnDesc.replace('{column}', columnDef.header)
|
|
25
|
+
: localization.sortedByColumnAsc.replace('{column}', columnDef.header)
|
|
30
26
|
: localization.unsorted;
|
|
31
27
|
|
|
32
28
|
return (
|
package/src/localization.ts
CHANGED
|
@@ -37,6 +37,7 @@ export interface MRT_Localization {
|
|
|
37
37
|
pinToLeft: string;
|
|
38
38
|
pinToRight: string;
|
|
39
39
|
resetColumnSize: string;
|
|
40
|
+
resetOrder: string;
|
|
40
41
|
rowActions: string;
|
|
41
42
|
rowNumber: string;
|
|
42
43
|
rowNumbers: string;
|
|
@@ -104,6 +105,7 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
104
105
|
pinToLeft: 'Pin to left',
|
|
105
106
|
pinToRight: 'Pin to right',
|
|
106
107
|
resetColumnSize: 'Reset column size',
|
|
108
|
+
resetOrder: 'Reset order',
|
|
107
109
|
rowActions: 'Row Actions',
|
|
108
110
|
rowNumber: '#',
|
|
109
111
|
rowNumbers: 'Row Numbers',
|
|
@@ -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_Column, MRT_TableInstance } from '..';
|
|
4
|
+
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
7
|
anchorEl: HTMLElement | null;
|
|
@@ -18,16 +18,16 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
18
18
|
}) => {
|
|
19
19
|
const {
|
|
20
20
|
getAllColumns,
|
|
21
|
+
getAllLeafColumns,
|
|
21
22
|
getIsAllColumnsVisible,
|
|
22
|
-
getIsSomeColumnsVisible,
|
|
23
23
|
getIsSomeColumnsPinned,
|
|
24
|
+
getIsSomeColumnsVisible,
|
|
24
25
|
getState,
|
|
25
26
|
toggleAllColumnsVisible,
|
|
26
|
-
|
|
27
|
-
options: { localization, enablePinning },
|
|
27
|
+
options: { localization, enablePinning, enableColumnOrdering },
|
|
28
28
|
} = tableInstance;
|
|
29
29
|
|
|
30
|
-
const { isDensePadding } = getState();
|
|
30
|
+
const { isDensePadding, columnOrder, columnPinning } = getState();
|
|
31
31
|
|
|
32
32
|
const hideAllColumns = () => {
|
|
33
33
|
getAllLeafColumns()
|
|
@@ -35,25 +35,19 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
35
35
|
.forEach((col) => col.toggleVisibility(false));
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
...dataColumns.filter((c) => c.getIsPinned() === false),
|
|
52
|
-
null,
|
|
53
|
-
...dataColumns.filter((c) => c.getIsPinned() === 'right'),
|
|
54
|
-
]
|
|
55
|
-
: dataColumns;
|
|
56
|
-
}, [getAllColumns(), getState().columnPinning, getIsSomeColumnsPinned()]);
|
|
38
|
+
const allColumns = useMemo(() => {
|
|
39
|
+
const columns = getAllColumns();
|
|
40
|
+
if (
|
|
41
|
+
columnOrder.length > 0 &&
|
|
42
|
+
!columns.some((col) => col.columnDefType === 'group')
|
|
43
|
+
) {
|
|
44
|
+
return (
|
|
45
|
+
columnOrder.map((colId) => columns.find((col) => col.id === colId)) ??
|
|
46
|
+
columns
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
return columns;
|
|
50
|
+
}, [getAllColumns(), columnOrder, columnPinning]) as MRT_Column[];
|
|
57
51
|
|
|
58
52
|
return (
|
|
59
53
|
<Menu
|
|
@@ -80,6 +74,11 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
80
74
|
{localization.hideAll}
|
|
81
75
|
</Button>
|
|
82
76
|
)}
|
|
77
|
+
{!isSubMenu && enableColumnOrdering && (
|
|
78
|
+
<Button onClick={() => tableInstance.resetColumnOrder()}>
|
|
79
|
+
{localization.resetOrder}
|
|
80
|
+
</Button>
|
|
81
|
+
)}
|
|
83
82
|
{!isSubMenu && enablePinning && (
|
|
84
83
|
<Button
|
|
85
84
|
disabled={!getIsSomeColumnsPinned()}
|
|
@@ -96,27 +95,15 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
96
95
|
</Button>
|
|
97
96
|
</Box>
|
|
98
97
|
<Divider />
|
|
99
|
-
{
|
|
98
|
+
{allColumns.map((column, index) => (
|
|
100
99
|
<MRT_ShowHideColumnsMenuItems
|
|
100
|
+
allColumns={allColumns}
|
|
101
101
|
column={column}
|
|
102
102
|
isSubMenu={isSubMenu}
|
|
103
103
|
key={`${index}-${column.id}`}
|
|
104
104
|
tableInstance={tableInstance}
|
|
105
105
|
/>
|
|
106
106
|
))}
|
|
107
|
-
<Divider />
|
|
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
|
-
)}
|
|
120
107
|
</Menu>
|
|
121
108
|
);
|
|
122
109
|
};
|