material-react-table 0.15.1 → 0.16.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/dist/MaterialReactTable.d.ts +10 -2
- package/dist/localization.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +75 -50
- 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 +76 -51
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/table/MRT_TableRoot.d.ts +1 -0
- package/dist/utils.d.ts +5 -5
- package/package.json +7 -7
- package/src/MaterialReactTable.tsx +17 -1
- package/src/body/MRT_TableBody.tsx +3 -3
- package/src/body/MRT_TableBodyCell.tsx +4 -2
- package/src/head/MRT_DraggableTableHeadCell.tsx +5 -7
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +0 -1
- package/src/inputs/MRT_FilterRangeFields.tsx +1 -14
- package/src/localization.ts +2 -2
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +64 -34
- package/src/table/MRT_TablePaper.tsx +3 -0
- package/src/table/MRT_TableRoot.tsx +27 -3
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +5 -1
- package/src/utils.ts +3 -9
package/dist/utils.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { ColumnDef, ColumnOrderState, Table
|
|
1
|
+
import { ColumnDef, ColumnOrderState, Table } from '@tanstack/react-table';
|
|
2
2
|
import { MaterialReactTableProps, MRT_Column, MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
3
|
export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
|
|
4
4
|
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
5
|
-
[key: string]: import("@tanstack/
|
|
5
|
+
[key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
|
|
6
6
|
}) => ColumnDef<D>;
|
|
7
7
|
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
|
-
[key: string]: import("@tanstack/
|
|
8
|
+
[key: string]: import("@tanstack/table-core").FilterFnOption<import("@tanstack/table-core").TableGenerics>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "accessorFn" | "columns" | "filterFn" | "footer" | "sortingFn" | "id" | "accessorKey" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "AggregatedCell" | "Cell" | "Edit" | "Filter" | "Footer" | "Header" | "enableClickToCopy" | "enableColumnActions" | "enableColumnFilterChangeMode" | "enableColumnOrdering" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChanged" | "onColumnFilterValueChanged" | "onColumnFilterValueChangedDebounced"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
|
13
|
-
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState
|
|
13
|
+
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState) => ColumnOrderState;
|
|
14
14
|
export declare const getLeadingDisplayColumnIds: (props: MaterialReactTableProps<any>) => string[];
|
|
15
15
|
export declare const getTrailingDisplayColumnIds: (props: MaterialReactTableProps<any>) => (string | false | undefined)[];
|
|
16
16
|
export declare const getDefaultColumnOrderIds: (props: MaterialReactTableProps<any>) => string[];
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.16.2",
|
|
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.",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
}
|
|
57
57
|
],
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@babel/core": "^7.18.
|
|
59
|
+
"@babel/core": "^7.18.6",
|
|
60
60
|
"@emotion/react": "^11.9.3",
|
|
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.6",
|
|
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",
|
|
@@ -77,8 +77,8 @@
|
|
|
77
77
|
"eslint-plugin-react-hooks": "^4.6.0",
|
|
78
78
|
"husky": "^8.0.1",
|
|
79
79
|
"prettier": "^2.7.1",
|
|
80
|
-
"react": "^
|
|
81
|
-
"react-dom": "^
|
|
80
|
+
"react": "^18.2.0",
|
|
81
|
+
"react-dom": "^18.2.0",
|
|
82
82
|
"react-is": "^18.2.0",
|
|
83
83
|
"rollup-plugin-commonjs": "^10.1.0",
|
|
84
84
|
"rollup-plugin-node-resolve": "^5.2.0",
|
|
@@ -97,8 +97,8 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/match-sorter-utils": "
|
|
101
|
-
"@tanstack/react-table": "
|
|
100
|
+
"@tanstack/match-sorter-utils": "8.0.13",
|
|
101
|
+
"@tanstack/react-table": "8.0.13",
|
|
102
102
|
"react-dnd": "^16.0.1",
|
|
103
103
|
"react-dnd-html5-backend": "^16.0.1",
|
|
104
104
|
"react-virtual": "^2.10.4"
|
|
@@ -30,6 +30,8 @@ import {
|
|
|
30
30
|
Cell,
|
|
31
31
|
Column,
|
|
32
32
|
ColumnDef,
|
|
33
|
+
ColumnOrderState,
|
|
34
|
+
ColumnPinningState,
|
|
33
35
|
FilterFn,
|
|
34
36
|
FilterFnOption,
|
|
35
37
|
Header,
|
|
@@ -205,9 +207,9 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
205
207
|
columns?: MRT_ColumnDef<D>[];
|
|
206
208
|
enableClickToCopy?: boolean;
|
|
207
209
|
enableColumnActions?: boolean;
|
|
210
|
+
enableColumnFilterChangeMode?: boolean;
|
|
208
211
|
enableColumnOrdering?: boolean;
|
|
209
212
|
enableEditing?: boolean;
|
|
210
|
-
enableColumnFilterChangeMode?: boolean;
|
|
211
213
|
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[] | null;
|
|
212
214
|
filterFn?: MRT_FilterFn;
|
|
213
215
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
@@ -646,6 +648,20 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
646
648
|
filterValue: any;
|
|
647
649
|
instance: MRT_TableInstance<D>;
|
|
648
650
|
}) => void;
|
|
651
|
+
onColumnOrderChanged?: ({
|
|
652
|
+
columnOrder,
|
|
653
|
+
instance,
|
|
654
|
+
}: {
|
|
655
|
+
columnOrder: ColumnOrderState;
|
|
656
|
+
instance: MRT_TableInstance<D>;
|
|
657
|
+
}) => void;
|
|
658
|
+
onColumnPinningChanged?: ({
|
|
659
|
+
columnPinning,
|
|
660
|
+
instance,
|
|
661
|
+
}: {
|
|
662
|
+
columnPinning: ColumnPinningState;
|
|
663
|
+
instance: MRT_TableInstance<D>;
|
|
664
|
+
}) => void;
|
|
649
665
|
onColumnVisibilityChanged?: ({
|
|
650
666
|
column,
|
|
651
667
|
columnVisibility,
|
|
@@ -12,7 +12,7 @@ interface Props {
|
|
|
12
12
|
|
|
13
13
|
export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
14
14
|
const {
|
|
15
|
-
|
|
15
|
+
getRowModel,
|
|
16
16
|
getPrePaginationRowModel,
|
|
17
17
|
getState,
|
|
18
18
|
options: {
|
|
@@ -51,13 +51,13 @@ export const MRT_TableBody: FC<Props> = ({ instance, tableContainerRef }) => {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
return enablePagination
|
|
54
|
-
?
|
|
54
|
+
? getRowModel().rows
|
|
55
55
|
: getPrePaginationRowModel().rows;
|
|
56
56
|
}, [
|
|
57
57
|
enableGlobalFilterRankedResults,
|
|
58
58
|
(enableGlobalFilterRankedResults && globalFilter) || !enablePagination
|
|
59
59
|
? getPrePaginationRowModel().rows
|
|
60
|
-
:
|
|
60
|
+
: getRowModel().rows,
|
|
61
61
|
globalFilter,
|
|
62
62
|
]);
|
|
63
63
|
|
|
@@ -53,8 +53,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
53
53
|
|
|
54
54
|
const [, dropRef] = useDrop({
|
|
55
55
|
accept: 'column',
|
|
56
|
-
drop: (movingColumn: MRT_Column) =>
|
|
57
|
-
reorderColumn(movingColumn, column, columnOrder
|
|
56
|
+
drop: (movingColumn: MRT_Column) => {
|
|
57
|
+
const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
|
|
58
|
+
setColumnOrder(newColumnOrder);
|
|
59
|
+
},
|
|
58
60
|
});
|
|
59
61
|
|
|
60
62
|
const mTableCellBodyProps =
|
|
@@ -10,11 +10,7 @@ interface Props {
|
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
export const MRT_DraggableTableHeadCell: FC<Props> = ({ header, instance }) => {
|
|
13
|
-
const {
|
|
14
|
-
getState,
|
|
15
|
-
options: {},
|
|
16
|
-
setColumnOrder,
|
|
17
|
-
} = instance;
|
|
13
|
+
const { getState, setColumnOrder } = instance;
|
|
18
14
|
|
|
19
15
|
const { columnOrder } = getState();
|
|
20
16
|
|
|
@@ -22,8 +18,10 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({ header, instance }) => {
|
|
|
22
18
|
|
|
23
19
|
const [, dropRef] = useDrop({
|
|
24
20
|
accept: 'column',
|
|
25
|
-
drop: (movingColumn: MRT_Column) =>
|
|
26
|
-
reorderColumn(movingColumn, column, columnOrder
|
|
21
|
+
drop: (movingColumn: MRT_Column) => {
|
|
22
|
+
const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
|
|
23
|
+
setColumnOrder(newColumnOrder);
|
|
24
|
+
},
|
|
27
25
|
});
|
|
28
26
|
|
|
29
27
|
const [{ isDragging }, dragRef, previewRef] = useDrag({
|
|
@@ -36,7 +36,6 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({
|
|
|
36
36
|
touchAction: 'none',
|
|
37
37
|
transition: column.getIsResizing() ? undefined : 'all 0.2s ease-in-out',
|
|
38
38
|
userSelect: 'none',
|
|
39
|
-
zIndex: 2000,
|
|
40
39
|
'&:active': {
|
|
41
40
|
backgroundColor: theme.palette.info.main,
|
|
42
41
|
opacity: 1,
|
|
@@ -9,22 +9,9 @@ interface Props {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export const MRT_FilterRangeFields: FC<Props> = ({ header, instance }) => {
|
|
12
|
-
const {
|
|
13
|
-
options: { localization },
|
|
14
|
-
} = instance;
|
|
15
|
-
|
|
16
12
|
return (
|
|
17
|
-
<Box sx={{ display: 'grid', gridTemplateColumns: '6fr
|
|
13
|
+
<Box sx={{ display: 'grid', gridTemplateColumns: '6fr 6fr', gap: '1rem' }}>
|
|
18
14
|
<MRT_FilterTextField header={header} inputIndex={0} instance={instance} />
|
|
19
|
-
<Box
|
|
20
|
-
sx={{
|
|
21
|
-
width: '100%',
|
|
22
|
-
minWidth: '5ch',
|
|
23
|
-
textAlign: 'center',
|
|
24
|
-
}}
|
|
25
|
-
>
|
|
26
|
-
{localization.to}
|
|
27
|
-
</Box>
|
|
28
15
|
<MRT_FilterTextField header={header} inputIndex={1} instance={instance} />
|
|
29
16
|
</Box>
|
|
30
17
|
);
|
package/src/localization.ts
CHANGED
|
@@ -55,11 +55,11 @@ export interface MRT_Localization {
|
|
|
55
55
|
sortedByColumnAsc: string;
|
|
56
56
|
sortedByColumnDesc: string;
|
|
57
57
|
thenBy: string;
|
|
58
|
-
to: string;
|
|
59
58
|
toggleDensity: string;
|
|
60
59
|
toggleFullScreen: string;
|
|
61
60
|
toggleSelectAll: string;
|
|
62
61
|
toggleSelectRow: string;
|
|
62
|
+
toggleVisibility: string;
|
|
63
63
|
ungroupByColumn: string;
|
|
64
64
|
unpin: string;
|
|
65
65
|
unpinAll: string;
|
|
@@ -124,11 +124,11 @@ export const MRT_DefaultLocalization_EN: MRT_Localization = {
|
|
|
124
124
|
sortedByColumnAsc: 'Sorted by {column} ascending',
|
|
125
125
|
sortedByColumnDesc: 'Sorted by {column} descending',
|
|
126
126
|
thenBy: ', then by ',
|
|
127
|
-
to: 'to',
|
|
128
127
|
toggleDensity: 'Toggle density',
|
|
129
128
|
toggleFullScreen: 'Toggle full screen',
|
|
130
129
|
toggleSelectAll: 'Toggle select all',
|
|
131
130
|
toggleSelectRow: 'Toggle select row',
|
|
131
|
+
toggleVisibility: 'Toggle visibility',
|
|
132
132
|
ungroupByColumn: 'Ungroup by {column}',
|
|
133
133
|
unpin: 'Unpin',
|
|
134
134
|
unpinAll: 'Unpin all',
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
import React, { FC, Ref } from 'react';
|
|
2
2
|
import { useDrag, useDrop } from 'react-dnd';
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
Box,
|
|
5
|
+
FormControlLabel,
|
|
6
|
+
MenuItem,
|
|
7
|
+
Switch,
|
|
8
|
+
Tooltip,
|
|
9
|
+
Typography,
|
|
10
|
+
} from '@mui/material';
|
|
4
11
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
5
12
|
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
6
13
|
import { reorderColumn } from '../utils';
|
|
@@ -21,18 +28,25 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
21
28
|
}) => {
|
|
22
29
|
const {
|
|
23
30
|
getState,
|
|
24
|
-
options: {
|
|
31
|
+
options: {
|
|
32
|
+
enableColumnOrdering,
|
|
33
|
+
enableHiding,
|
|
34
|
+
enablePinning,
|
|
35
|
+
localization,
|
|
36
|
+
},
|
|
25
37
|
setColumnOrder,
|
|
26
38
|
} = instance;
|
|
27
39
|
|
|
28
|
-
const { columnOrder
|
|
40
|
+
const { columnOrder } = getState();
|
|
29
41
|
|
|
30
42
|
const { columnDef, columnDefType } = column;
|
|
31
43
|
|
|
32
44
|
const [, dropRef] = useDrop({
|
|
33
45
|
accept: 'column',
|
|
34
|
-
drop: (movingColumn: MRT_Column) =>
|
|
35
|
-
reorderColumn(movingColumn, column, columnOrder
|
|
46
|
+
drop: (movingColumn: MRT_Column) => {
|
|
47
|
+
const newColumnOrder = reorderColumn(movingColumn, column, columnOrder);
|
|
48
|
+
setColumnOrder(newColumnOrder);
|
|
49
|
+
},
|
|
36
50
|
});
|
|
37
51
|
|
|
38
52
|
const [, dragRef, previewRef] = useDrag({
|
|
@@ -56,11 +70,6 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
56
70
|
} else {
|
|
57
71
|
column.toggleVisibility();
|
|
58
72
|
}
|
|
59
|
-
onColumnVisibilityChanged?.({
|
|
60
|
-
column,
|
|
61
|
-
columnVisibility,
|
|
62
|
-
instance,
|
|
63
|
-
});
|
|
64
73
|
};
|
|
65
74
|
|
|
66
75
|
return (
|
|
@@ -85,35 +94,56 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
85
94
|
>
|
|
86
95
|
{columnDefType !== 'group' &&
|
|
87
96
|
enableColumnOrdering &&
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
!allColumns.some((col) => col.columnDefType === 'group') &&
|
|
98
|
+
(columnDef.enableColumnOrdering !== false ? (
|
|
90
99
|
<MRT_GrabHandleButton
|
|
91
100
|
ref={dragRef as Ref<HTMLButtonElement>}
|
|
92
101
|
instance={instance}
|
|
93
102
|
/>
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
) : (
|
|
104
|
+
<Box sx={{ width: '28px' }} />
|
|
105
|
+
))}
|
|
106
|
+
{enablePinning &&
|
|
107
|
+
!isSubMenu &&
|
|
108
|
+
(column.getCanPin() ? (
|
|
109
|
+
<MRT_ColumnPinningButtons column={column} instance={instance} />
|
|
110
|
+
) : (
|
|
111
|
+
<Box sx={{ width: '70px' }} />
|
|
112
|
+
))}
|
|
113
|
+
{enableHiding ? (
|
|
114
|
+
<FormControlLabel
|
|
115
|
+
componentsProps={{
|
|
116
|
+
typography: {
|
|
117
|
+
sx: {
|
|
118
|
+
mb: 0,
|
|
119
|
+
opacity: columnDefType !== 'display' ? 1 : 0.5,
|
|
120
|
+
},
|
|
104
121
|
},
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
122
|
+
}}
|
|
123
|
+
checked={switchChecked}
|
|
124
|
+
control={
|
|
125
|
+
<Tooltip
|
|
126
|
+
arrow
|
|
127
|
+
enterDelay={1000}
|
|
128
|
+
enterNextDelay={1000}
|
|
129
|
+
title={localization.toggleVisibility}
|
|
130
|
+
>
|
|
131
|
+
<Switch />
|
|
132
|
+
</Tooltip>
|
|
133
|
+
}
|
|
134
|
+
disabled={
|
|
135
|
+
(isSubMenu && switchChecked) ||
|
|
136
|
+
!column.getCanHide() ||
|
|
137
|
+
column.getIsGrouped()
|
|
138
|
+
}
|
|
139
|
+
label={columnDef.header}
|
|
140
|
+
onChange={() => handleToggleColumnHidden(column)}
|
|
141
|
+
/>
|
|
142
|
+
) : (
|
|
143
|
+
<Typography sx={{ alignSelf: 'center' }}>
|
|
144
|
+
{columnDef.header}
|
|
145
|
+
</Typography>
|
|
146
|
+
)}
|
|
117
147
|
</Box>
|
|
118
148
|
</MenuItem>
|
|
119
149
|
{column.columns?.map((c: MRT_Column, i) => (
|
|
@@ -42,6 +42,9 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
|
|
|
42
42
|
sx={{
|
|
43
43
|
transition: 'all 0.2s ease-in-out',
|
|
44
44
|
...tablePaperProps?.sx,
|
|
45
|
+
}}
|
|
46
|
+
style={{
|
|
47
|
+
...tablePaperProps?.style,
|
|
45
48
|
height: isFullScreen ? '100vh' : undefined,
|
|
46
49
|
margin: isFullScreen ? '0' : undefined,
|
|
47
50
|
maxHeight: isFullScreen ? '100vh' : undefined,
|
|
@@ -168,7 +168,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
168
168
|
id: 'mrt-expand',
|
|
169
169
|
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
170
170
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
171
|
-
size:
|
|
171
|
+
size: 60,
|
|
172
172
|
}),
|
|
173
173
|
columnOrder.includes('mrt-select') &&
|
|
174
174
|
createDisplayColumn(table, {
|
|
@@ -183,7 +183,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
183
183
|
id: 'mrt-select',
|
|
184
184
|
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
185
185
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
186
|
-
size:
|
|
186
|
+
size: 60,
|
|
187
187
|
}),
|
|
188
188
|
columnOrder.includes('mrt-row-numbers') &&
|
|
189
189
|
createDisplayColumn(table, {
|
|
@@ -193,7 +193,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
193
193
|
id: 'mrt-row-numbers',
|
|
194
194
|
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
195
195
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
196
|
-
size:
|
|
196
|
+
size: 60,
|
|
197
197
|
}),
|
|
198
198
|
].filter(Boolean) as MRT_ColumnDef<D>[];
|
|
199
199
|
}, [
|
|
@@ -310,6 +310,30 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
310
310
|
instance,
|
|
311
311
|
]);
|
|
312
312
|
|
|
313
|
+
useEffect(() => {
|
|
314
|
+
props?.onColumnOrderChanged?.({
|
|
315
|
+
columnOrder: instance.getState().columnOrder,
|
|
316
|
+
//@ts-ignore
|
|
317
|
+
instance,
|
|
318
|
+
});
|
|
319
|
+
}, [instance.getState().columnOrder]);
|
|
320
|
+
|
|
321
|
+
useEffect(() => {
|
|
322
|
+
props?.onColumnPinningChanged?.({
|
|
323
|
+
columnPinning: instance.getState().columnPinning,
|
|
324
|
+
//@ts-ignore
|
|
325
|
+
instance,
|
|
326
|
+
});
|
|
327
|
+
}, [instance.getState().columnPinning]);
|
|
328
|
+
|
|
329
|
+
useEffect(() => {
|
|
330
|
+
props?.onColumnVisibilityChanged?.({
|
|
331
|
+
columnPinning: instance.getState().columnVisibility,
|
|
332
|
+
//@ts-ignore
|
|
333
|
+
instance,
|
|
334
|
+
});
|
|
335
|
+
}, [instance.getState().columnVisibility]);
|
|
336
|
+
|
|
313
337
|
return (
|
|
314
338
|
<>
|
|
315
339
|
<Dialog
|
|
@@ -16,11 +16,13 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
|
|
|
16
16
|
const {
|
|
17
17
|
options: {
|
|
18
18
|
enableColumnFilters,
|
|
19
|
+
enableColumnOrdering,
|
|
19
20
|
enableDensityToggle,
|
|
20
21
|
enableFilters,
|
|
21
22
|
enableFullScreenToggle,
|
|
22
23
|
enableGlobalFilter,
|
|
23
24
|
enableHiding,
|
|
25
|
+
enablePinning,
|
|
24
26
|
positionGlobalFilter,
|
|
25
27
|
renderToolbarInternalActions,
|
|
26
28
|
},
|
|
@@ -52,7 +54,9 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
|
|
|
52
54
|
{enableFilters && enableColumnFilters && (
|
|
53
55
|
<MRT_ToggleFiltersButton instance={instance} />
|
|
54
56
|
)}
|
|
55
|
-
{enableHiding
|
|
57
|
+
{(enableHiding || enableColumnOrdering || enablePinning) && (
|
|
58
|
+
<MRT_ShowHideColumnsButton instance={instance} />
|
|
59
|
+
)}
|
|
56
60
|
{enableDensityToggle && (
|
|
57
61
|
<MRT_ToggleDensePaddingButton instance={instance} />
|
|
58
62
|
)}
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ColumnDef,
|
|
3
|
-
ColumnOrderState,
|
|
4
|
-
Table,
|
|
5
|
-
Updater,
|
|
6
|
-
} from '@tanstack/react-table';
|
|
1
|
+
import { ColumnDef, ColumnOrderState, Table } from '@tanstack/react-table';
|
|
7
2
|
import {
|
|
8
3
|
MaterialReactTableProps,
|
|
9
4
|
MRT_Column,
|
|
@@ -67,8 +62,7 @@ export const reorderColumn = (
|
|
|
67
62
|
movingColumn: MRT_Column,
|
|
68
63
|
receivingColumn: MRT_Column,
|
|
69
64
|
columnOrder: ColumnOrderState,
|
|
70
|
-
|
|
71
|
-
) => {
|
|
65
|
+
): ColumnOrderState => {
|
|
72
66
|
if (movingColumn.getCanPin()) {
|
|
73
67
|
movingColumn.pin(receivingColumn.getIsPinned());
|
|
74
68
|
}
|
|
@@ -77,7 +71,7 @@ export const reorderColumn = (
|
|
|
77
71
|
0,
|
|
78
72
|
columnOrder.splice(columnOrder.indexOf(movingColumn.id), 1)[0],
|
|
79
73
|
);
|
|
80
|
-
|
|
74
|
+
return [...columnOrder];
|
|
81
75
|
};
|
|
82
76
|
|
|
83
77
|
export const getLeadingDisplayColumnIds = (
|