material-react-table 0.8.12 → 0.8.15
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/README.md +1 -0
- package/dist/MaterialReactTable.d.ts +6 -2
- package/dist/buttons/MRT_GrabHandleButton.d.ts +8 -0
- package/dist/material-react-table.cjs.development.js +1893 -1816
- 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 +220 -143
- package/dist/material-react-table.esm.js.map +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 +4 -3
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +9 -0
- package/src/body/MRT_TableBodyCell.tsx +15 -1
- package/src/buttons/MRT_ColumnPinningButtons.tsx +1 -1
- package/src/{head/MRT_TableHeadCellGrabHandle.tsx → buttons/MRT_GrabHandleButton.tsx} +2 -3
- package/src/footer/MRT_TableFooterCell.tsx +6 -6
- package/src/head/MRT_DraggableTableHeadCell.tsx +8 -17
- package/src/head/MRT_TableHeadCell.tsx +14 -13
- package/src/inputs/MRT_SelectCheckbox.tsx +6 -1
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +19 -5
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +68 -24
- package/src/table/MRT_TableRoot.tsx +33 -15
- package/src/utils.ts +24 -2
- package/dist/head/MRT_TableHeadCellGrabHandle.d.ts +0 -9
package/dist/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import { MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
1
|
+
import { ColumnDef, ColumnOrderState, Table, Updater } from '@tanstack/react-table';
|
|
2
|
+
import { 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
5
|
[key: string]: MRT_FilterFn<{}>;
|
|
@@ -7,6 +7,7 @@ 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>;
|
|
13
|
+
export declare const reorderColumn: (movingColumn: MRT_Column, receivingColumn: MRT_Column, columnOrder: ColumnOrderState, setColumnOrder: (updater: Updater<ColumnOrderState>) => void) => void;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.8.
|
|
2
|
+
"version": "0.8.15",
|
|
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.",
|
|
@@ -80,11 +80,14 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
80
80
|
| 'getAllColumns'
|
|
81
81
|
| 'getAllFlatColumns'
|
|
82
82
|
| 'getAllLeafColumns'
|
|
83
|
+
| 'getCenterLeafColumns'
|
|
83
84
|
| 'getColumn'
|
|
84
85
|
| 'getExpandedRowModel'
|
|
85
86
|
| 'getFlatHeaders'
|
|
87
|
+
| 'getLeftLeafColumns'
|
|
86
88
|
| 'getPaginationRowModel'
|
|
87
89
|
| 'getPrePaginationRowModel'
|
|
90
|
+
| 'getRightLeafColumns'
|
|
88
91
|
| 'getRowModel'
|
|
89
92
|
| 'getSelectedRowModel'
|
|
90
93
|
| 'getState'
|
|
@@ -93,11 +96,14 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
93
96
|
getAllColumns: () => MRT_Column<D>[];
|
|
94
97
|
getAllFlatColumns: () => MRT_Column<D>[];
|
|
95
98
|
getAllLeafColumns: () => MRT_Column<D>[];
|
|
99
|
+
getCenterLeafColumns: () => MRT_Column<D>[];
|
|
96
100
|
getColumn: (columnId: string) => MRT_Column<D>;
|
|
97
101
|
getExpandedRowModel: () => MRT_RowModel<D>;
|
|
98
102
|
getFlatHeaders: () => MRT_Header<D>[];
|
|
103
|
+
getLeftLeafColumns: () => MRT_Column<D>[];
|
|
99
104
|
getPaginationRowModel: () => MRT_RowModel<D>;
|
|
100
105
|
getPrePaginationRowModel: () => MRT_RowModel<D>;
|
|
106
|
+
getRightLeafColumns: () => MRT_Column<D>[];
|
|
101
107
|
getRowModel: () => MRT_RowModel<D>;
|
|
102
108
|
getSelectedRowModel: () => MRT_RowModel<D>;
|
|
103
109
|
getState: () => MRT_TableState<D>;
|
|
@@ -760,6 +766,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
760
766
|
IconButtonProps & { tableInstance: MRT_TableInstance<D> }
|
|
761
767
|
>;
|
|
762
768
|
}) => ReactNode;
|
|
769
|
+
selectAllMode?: 'all' | 'page';
|
|
763
770
|
};
|
|
764
771
|
|
|
765
772
|
export default <D extends Record<string, any> = {}>({
|
|
@@ -796,6 +803,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
796
803
|
positionPagination = 'bottom',
|
|
797
804
|
positionToolbarActions = 'top',
|
|
798
805
|
positionToolbarAlertBanner = 'top',
|
|
806
|
+
selectAllMode = 'all',
|
|
799
807
|
...rest
|
|
800
808
|
}: MaterialReactTableProps<D>) => (
|
|
801
809
|
<MRT_TableRoot
|
|
@@ -832,6 +840,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
832
840
|
positionPagination={positionPagination}
|
|
833
841
|
positionToolbarActions={positionToolbarActions}
|
|
834
842
|
positionToolbarAlertBanner={positionToolbarAlertBanner}
|
|
843
|
+
selectAllMode={selectAllMode}
|
|
835
844
|
{...rest}
|
|
836
845
|
/>
|
|
837
846
|
);
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useMemo } from 'react';
|
|
2
|
+
import { useDrop } from 'react-dnd';
|
|
2
3
|
import { alpha, darken, lighten, Skeleton, TableCell } from '@mui/material';
|
|
3
4
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
4
|
-
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
5
5
|
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
|
6
|
+
import { reorderColumn } from '../utils';
|
|
7
|
+
import type { MRT_Cell, MRT_Column, MRT_TableInstance } from '..';
|
|
6
8
|
|
|
7
9
|
interface Props {
|
|
8
10
|
cell: MRT_Cell;
|
|
@@ -20,16 +22,19 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
20
22
|
options: {
|
|
21
23
|
editingMode,
|
|
22
24
|
enableClickToCopy,
|
|
25
|
+
enableColumnOrdering,
|
|
23
26
|
enableEditing,
|
|
24
27
|
idPrefix,
|
|
25
28
|
muiTableBodyCellProps,
|
|
26
29
|
muiTableBodyCellSkeletonProps,
|
|
27
30
|
onCellClick,
|
|
28
31
|
},
|
|
32
|
+
setColumnOrder,
|
|
29
33
|
setCurrentEditingCell,
|
|
30
34
|
} = tableInstance;
|
|
31
35
|
|
|
32
36
|
const {
|
|
37
|
+
columnOrder,
|
|
33
38
|
currentEditingCell,
|
|
34
39
|
currentEditingRow,
|
|
35
40
|
isDensePadding,
|
|
@@ -41,6 +46,12 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
41
46
|
|
|
42
47
|
const { columnDef, columnDefType } = column;
|
|
43
48
|
|
|
49
|
+
const [, dropRef] = useDrop({
|
|
50
|
+
accept: 'column',
|
|
51
|
+
drop: (movingColumn: MRT_Column) =>
|
|
52
|
+
reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
|
|
53
|
+
});
|
|
54
|
+
|
|
44
55
|
const mTableCellBodyProps =
|
|
45
56
|
muiTableBodyCellProps instanceof Function
|
|
46
57
|
? muiTableBodyCellProps({ cell, tableInstance })
|
|
@@ -121,6 +132,9 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
121
132
|
}
|
|
122
133
|
onDoubleClick={handleDoubleClick}
|
|
123
134
|
{...tableCellProps}
|
|
135
|
+
ref={
|
|
136
|
+
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
137
|
+
}
|
|
124
138
|
sx={(theme) => ({
|
|
125
139
|
backgroundColor: column.getIsPinned()
|
|
126
140
|
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
@@ -23,7 +23,7 @@ export const MRT_ColumnPinningButtons: FC<Props> = ({
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
return (
|
|
26
|
-
<Box sx={{
|
|
26
|
+
<Box sx={{ minWidth: '70px', textAlign: 'center' }}>
|
|
27
27
|
{column.getIsPinned() ? (
|
|
28
28
|
<Tooltip arrow title={localization.unpin}>
|
|
29
29
|
<IconButton onClick={() => handlePinColumn(false)} size="small">
|
|
@@ -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: {
|
|
@@ -59,12 +59,12 @@ export const MRT_TableFooterCell: FC<Props> = ({ footer, tableInstance }) => {
|
|
|
59
59
|
<>
|
|
60
60
|
{footer.isPlaceholder
|
|
61
61
|
? null
|
|
62
|
-
: columnDef.Footer instanceof Function
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
: (columnDef.Footer instanceof Function
|
|
63
|
+
? columnDef.Footer?.({
|
|
64
|
+
footer,
|
|
65
|
+
tableInstance,
|
|
66
|
+
})
|
|
67
|
+
: columnDef.Footer) ??
|
|
68
68
|
columnDef.footer ??
|
|
69
69
|
footer.renderFooter() ??
|
|
70
70
|
null}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { useDrag, useDrop } from 'react-dnd';
|
|
3
3
|
import { MRT_TableHeadCell } from './MRT_TableHeadCell';
|
|
4
|
-
import type { MRT_Header, MRT_TableInstance } from '..';
|
|
4
|
+
import type { MRT_Column, MRT_Header, MRT_TableInstance } from '..';
|
|
5
|
+
import { reorderColumn } from '../utils';
|
|
5
6
|
|
|
6
7
|
interface Props {
|
|
7
8
|
header: MRT_Header;
|
|
@@ -20,30 +21,20 @@ export const MRT_DraggableTableHeadCell: FC<Props> = ({
|
|
|
20
21
|
|
|
21
22
|
const { columnOrder } = getState();
|
|
22
23
|
|
|
23
|
-
const
|
|
24
|
-
if (movingHeader.column.getCanPin()) {
|
|
25
|
-
movingHeader.column.pin(receivingHeader.column.getIsPinned());
|
|
26
|
-
}
|
|
27
|
-
const { index: currentIndex } = movingHeader;
|
|
28
|
-
columnOrder.splice(
|
|
29
|
-
receivingHeader.index,
|
|
30
|
-
0,
|
|
31
|
-
columnOrder.splice(currentIndex, 1)[0],
|
|
32
|
-
);
|
|
33
|
-
setColumnOrder([...columnOrder]);
|
|
34
|
-
};
|
|
24
|
+
const { column } = header;
|
|
35
25
|
|
|
36
26
|
const [, dropRef] = useDrop({
|
|
37
|
-
accept: '
|
|
38
|
-
drop: (
|
|
27
|
+
accept: 'column',
|
|
28
|
+
drop: (movingColumn: MRT_Column) =>
|
|
29
|
+
reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
|
|
39
30
|
});
|
|
40
31
|
|
|
41
32
|
const [{ isDragging }, dragRef, previewRef] = useDrag({
|
|
42
33
|
collect: (monitor) => ({
|
|
43
34
|
isDragging: monitor.isDragging(),
|
|
44
35
|
}),
|
|
45
|
-
item: () =>
|
|
46
|
-
type: '
|
|
36
|
+
item: () => column,
|
|
37
|
+
type: 'column',
|
|
47
38
|
});
|
|
48
39
|
|
|
49
40
|
return (
|
|
@@ -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';
|
|
@@ -58,14 +58,14 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
58
58
|
...mcTableHeadCellProps,
|
|
59
59
|
};
|
|
60
60
|
|
|
61
|
-
const headerElement = (
|
|
62
|
-
columnDef?.Header
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
61
|
+
const headerElement = ((columnDef?.Header instanceof Function
|
|
62
|
+
? columnDef?.Header?.({
|
|
63
|
+
header,
|
|
64
|
+
tableInstance,
|
|
65
|
+
})
|
|
66
|
+
: columnDef?.Header) ??
|
|
67
|
+
header.renderHeader() ??
|
|
68
|
+
columnDef.header) as ReactNode;
|
|
69
69
|
|
|
70
70
|
const getIsLastLeftPinnedColumn = () => {
|
|
71
71
|
return (
|
|
@@ -92,7 +92,9 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
92
92
|
align={columnDefType === 'group' ? 'center' : 'left'}
|
|
93
93
|
colSpan={header.colSpan}
|
|
94
94
|
{...tableCellProps}
|
|
95
|
-
ref={
|
|
95
|
+
ref={
|
|
96
|
+
columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
|
|
97
|
+
}
|
|
96
98
|
sx={(theme: Theme) => ({
|
|
97
99
|
backgroundColor:
|
|
98
100
|
column.getIsPinned() && columnDefType !== 'group'
|
|
@@ -123,7 +125,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
123
125
|
column.getIsPinned() && columnDefType !== 'group'
|
|
124
126
|
? 'sticky'
|
|
125
127
|
: undefined,
|
|
126
|
-
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.
|
|
128
|
+
pt: columnDefType !== 'data' ? 0 : isDensePadding ? '0.25' : '.75rem',
|
|
127
129
|
right:
|
|
128
130
|
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
129
131
|
transition: `all ${enableColumnResizing ? 0 : '0.2s'} ease-in-out`,
|
|
@@ -190,8 +192,7 @@ export const MRT_TableHeadCell: FC<Props> = ({
|
|
|
190
192
|
((enableColumnOrdering &&
|
|
191
193
|
columnDef.enableColumnOrdering !== false) ||
|
|
192
194
|
(enableGrouping && columnDef.enableGrouping !== false)) && (
|
|
193
|
-
<
|
|
194
|
-
header={header}
|
|
195
|
+
<MRT_GrabHandleButton
|
|
195
196
|
ref={dragRef as Ref<HTMLButtonElement>}
|
|
196
197
|
tableInstance={tableInstance}
|
|
197
198
|
/>
|
|
@@ -22,6 +22,7 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
22
22
|
muiSelectCheckboxProps,
|
|
23
23
|
onSelectChange,
|
|
24
24
|
onSelectAllChange,
|
|
25
|
+
selectAllMode,
|
|
25
26
|
},
|
|
26
27
|
} = tableInstance;
|
|
27
28
|
|
|
@@ -29,7 +30,11 @@ export const MRT_SelectCheckbox: FC<Props> = ({
|
|
|
29
30
|
|
|
30
31
|
const handleSelectChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
31
32
|
if (selectAll) {
|
|
32
|
-
|
|
33
|
+
if (selectAllMode === 'all') {
|
|
34
|
+
tableInstance.getToggleAllRowsSelectedHandler()(event as any);
|
|
35
|
+
} else if (selectAllMode === 'page') {
|
|
36
|
+
tableInstance.getToggleAllPageRowsSelectedHandler()(event as any);
|
|
37
|
+
}
|
|
33
38
|
onSelectAllChange?.({
|
|
34
39
|
event,
|
|
35
40
|
selectedRows: event.target.checked ? getRowModel().flatRows : [],
|
|
@@ -19,9 +19,12 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
19
19
|
const {
|
|
20
20
|
getAllColumns,
|
|
21
21
|
getAllLeafColumns,
|
|
22
|
+
getCenterLeafColumns,
|
|
22
23
|
getIsAllColumnsVisible,
|
|
23
24
|
getIsSomeColumnsPinned,
|
|
24
25
|
getIsSomeColumnsVisible,
|
|
26
|
+
getLeftLeafColumns,
|
|
27
|
+
getRightLeafColumns,
|
|
25
28
|
getState,
|
|
26
29
|
toggleAllColumnsVisible,
|
|
27
30
|
options: { localization, enablePinning, enableColumnOrdering },
|
|
@@ -41,13 +44,23 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
41
44
|
columnOrder.length > 0 &&
|
|
42
45
|
!columns.some((col) => col.columnDefType === 'group')
|
|
43
46
|
) {
|
|
44
|
-
return
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
47
|
+
return [
|
|
48
|
+
...getLeftLeafColumns(),
|
|
49
|
+
...[...new Set(columnOrder)].map((colId) =>
|
|
50
|
+
getCenterLeafColumns().find((col) => col?.id === colId),
|
|
51
|
+
),
|
|
52
|
+
...getRightLeafColumns(),
|
|
53
|
+
].filter(Boolean);
|
|
48
54
|
}
|
|
49
55
|
return columns;
|
|
50
|
-
}, [
|
|
56
|
+
}, [
|
|
57
|
+
columnOrder,
|
|
58
|
+
columnPinning,
|
|
59
|
+
getAllColumns(),
|
|
60
|
+
getCenterLeafColumns(),
|
|
61
|
+
getLeftLeafColumns(),
|
|
62
|
+
getRightLeafColumns(),
|
|
63
|
+
]) as MRT_Column[];
|
|
51
64
|
|
|
52
65
|
return (
|
|
53
66
|
<Menu
|
|
@@ -97,6 +110,7 @@ export const MRT_ShowHideColumnsMenu: FC<Props> = ({
|
|
|
97
110
|
<Divider />
|
|
98
111
|
{allColumns.map((column, index) => (
|
|
99
112
|
<MRT_ShowHideColumnsMenuItems
|
|
113
|
+
allColumns={allColumns}
|
|
100
114
|
column={column}
|
|
101
115
|
isSubMenu={isSubMenu}
|
|
102
116
|
key={`${index}-${column.id}`}
|
|
@@ -1,28 +1,48 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import React, { FC, Ref } from 'react';
|
|
2
|
+
import { useDrag, useDrop } from 'react-dnd';
|
|
3
|
+
import { Box, FormControlLabel, MenuItem, Switch } from '@mui/material';
|
|
3
4
|
import { MRT_ColumnPinningButtons } from '../buttons/MRT_ColumnPinningButtons';
|
|
5
|
+
import { MRT_GrabHandleButton } from '../buttons/MRT_GrabHandleButton';
|
|
6
|
+
import { reorderColumn } from '../utils';
|
|
4
7
|
import type { MRT_Column, MRT_TableInstance } from '..';
|
|
5
8
|
|
|
6
9
|
interface Props {
|
|
10
|
+
allColumns: MRT_Column[];
|
|
7
11
|
column: MRT_Column;
|
|
8
12
|
isSubMenu?: boolean;
|
|
9
13
|
tableInstance: MRT_TableInstance;
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
17
|
+
allColumns,
|
|
13
18
|
column,
|
|
14
19
|
isSubMenu,
|
|
15
20
|
tableInstance,
|
|
16
21
|
}) => {
|
|
17
22
|
const {
|
|
18
23
|
getState,
|
|
19
|
-
options: { onToggleColumnVisibility },
|
|
24
|
+
options: { enableColumnOrdering, onToggleColumnVisibility },
|
|
25
|
+
setColumnOrder,
|
|
20
26
|
} = tableInstance;
|
|
21
27
|
|
|
22
|
-
const { columnVisibility } = getState();
|
|
28
|
+
const { columnOrder, columnVisibility } = getState();
|
|
23
29
|
|
|
24
30
|
const { columnDef, columnDefType } = column;
|
|
25
31
|
|
|
32
|
+
const [, dropRef] = useDrop({
|
|
33
|
+
accept: 'column',
|
|
34
|
+
drop: (movingColumn: MRT_Column) =>
|
|
35
|
+
reorderColumn(movingColumn, column, columnOrder, setColumnOrder),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const [, dragRef, previewRef] = useDrag({
|
|
39
|
+
collect: (monitor) => ({
|
|
40
|
+
isDragging: monitor.isDragging(),
|
|
41
|
+
}),
|
|
42
|
+
item: () => column,
|
|
43
|
+
type: 'column',
|
|
44
|
+
});
|
|
45
|
+
|
|
26
46
|
const switchChecked =
|
|
27
47
|
(columnDefType !== 'group' && column.getIsVisible()) ||
|
|
28
48
|
(columnDefType === 'group' &&
|
|
@@ -46,6 +66,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
46
66
|
return (
|
|
47
67
|
<>
|
|
48
68
|
<MenuItem
|
|
69
|
+
ref={columnDefType === 'data' ? dropRef : undefined}
|
|
49
70
|
sx={{
|
|
50
71
|
alignItems: 'center',
|
|
51
72
|
justifyContent: 'flex-start',
|
|
@@ -54,30 +75,53 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
|
54
75
|
py: '6px',
|
|
55
76
|
}}
|
|
56
77
|
>
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
<FormControlLabel
|
|
64
|
-
componentsProps={{
|
|
65
|
-
typography: {
|
|
66
|
-
sx: {
|
|
67
|
-
marginBottom: 0,
|
|
68
|
-
opacity: columnDefType !== 'display' ? 1 : 0.5,
|
|
69
|
-
},
|
|
70
|
-
},
|
|
78
|
+
<Box
|
|
79
|
+
ref={previewRef}
|
|
80
|
+
sx={{
|
|
81
|
+
display: 'flex',
|
|
82
|
+
flexWrap: 'nowrap',
|
|
83
|
+
gap: '8px',
|
|
71
84
|
}}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
85
|
+
>
|
|
86
|
+
{columnDefType !== 'group' &&
|
|
87
|
+
enableColumnOrdering &&
|
|
88
|
+
columnDef.enableColumnOrdering !== false &&
|
|
89
|
+
!allColumns.some((col) => col.columnDefType === 'group') && (
|
|
90
|
+
<MRT_GrabHandleButton
|
|
91
|
+
ref={dragRef as Ref<HTMLButtonElement>}
|
|
92
|
+
tableInstance={tableInstance}
|
|
93
|
+
/>
|
|
94
|
+
)}
|
|
95
|
+
{!isSubMenu && column.getCanPin() && (
|
|
96
|
+
<MRT_ColumnPinningButtons
|
|
97
|
+
column={column}
|
|
98
|
+
tableInstance={tableInstance}
|
|
99
|
+
/>
|
|
100
|
+
)}
|
|
101
|
+
<FormControlLabel
|
|
102
|
+
componentsProps={{
|
|
103
|
+
typography: {
|
|
104
|
+
sx: {
|
|
105
|
+
mb: 0,
|
|
106
|
+
opacity: columnDefType !== 'display' ? 1 : 0.5,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
}}
|
|
110
|
+
checked={switchChecked}
|
|
111
|
+
control={<Switch />}
|
|
112
|
+
disabled={
|
|
113
|
+
(isSubMenu && switchChecked) ||
|
|
114
|
+
!column.getCanHide() ||
|
|
115
|
+
column.getIsGrouped()
|
|
116
|
+
}
|
|
117
|
+
label={columnDef.header}
|
|
118
|
+
onChange={() => handleToggleColumnHidden(column)}
|
|
119
|
+
/>
|
|
120
|
+
</Box>
|
|
78
121
|
</MenuItem>
|
|
79
122
|
{column.columns?.map((c: MRT_Column, i) => (
|
|
80
123
|
<MRT_ShowHideColumnsMenuItems
|
|
124
|
+
allColumns={allColumns}
|
|
81
125
|
key={`${i}-${c.id}`}
|
|
82
126
|
column={c}
|
|
83
127
|
isSubMenu={isSubMenu}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
ReactTableGenerics,
|
|
13
13
|
getFacetedRowModel,
|
|
14
14
|
TableState,
|
|
15
|
+
Table,
|
|
15
16
|
} from '@tanstack/react-table';
|
|
16
17
|
import {
|
|
17
18
|
MRT_Cell,
|
|
@@ -57,7 +58,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
57
58
|
const initState = props.initialState ?? {};
|
|
58
59
|
|
|
59
60
|
initState.columnOrder =
|
|
60
|
-
initState?.columnOrder ??
|
|
61
|
+
initState?.columnOrder ??
|
|
62
|
+
(props.enableColumnOrdering || props.enableGrouping)
|
|
61
63
|
? ([
|
|
62
64
|
showActionColumn && 'mrt-row-actions',
|
|
63
65
|
showExpandColumn && 'mrt-expand',
|
|
@@ -133,7 +135,25 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
133
135
|
MRT_FILTER_OPTION | FilterFn<ReactTableGenerics> | string | number | symbol
|
|
134
136
|
>(props.globalFilterFn ?? MRT_FILTER_OPTION.FUZZY);
|
|
135
137
|
|
|
136
|
-
const table = useMemo(
|
|
138
|
+
const table = useMemo(
|
|
139
|
+
() =>
|
|
140
|
+
// @ts-ignore
|
|
141
|
+
createTable().setOptions({
|
|
142
|
+
//@ts-ignore
|
|
143
|
+
filterFns: defaultFilterFNs,
|
|
144
|
+
getCoreRowModel: getCoreRowModel(),
|
|
145
|
+
getExpandedRowModel: getExpandedRowModel(),
|
|
146
|
+
getFacetedRowModel: getFacetedRowModel(),
|
|
147
|
+
getFilteredRowModel: getFilteredRowModel(),
|
|
148
|
+
getGroupedRowModel: getGroupedRowModel(),
|
|
149
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
150
|
+
getSortedRowModel: getSortedRowModel(),
|
|
151
|
+
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
152
|
+
idPrefix,
|
|
153
|
+
initialState,
|
|
154
|
+
}) as Table<D>,
|
|
155
|
+
[],
|
|
156
|
+
);
|
|
137
157
|
|
|
138
158
|
const displayColumns = useMemo(
|
|
139
159
|
() =>
|
|
@@ -148,6 +168,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
148
168
|
),
|
|
149
169
|
header: props.localization?.actions,
|
|
150
170
|
id: 'mrt-row-actions',
|
|
171
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
172
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
151
173
|
size: 60,
|
|
152
174
|
}),
|
|
153
175
|
showExpandColumn &&
|
|
@@ -164,6 +186,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
164
186
|
) : null,
|
|
165
187
|
header: props.localization?.expand,
|
|
166
188
|
id: 'mrt-expand',
|
|
189
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
190
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
167
191
|
size: 50,
|
|
168
192
|
}),
|
|
169
193
|
props.enableRowSelection &&
|
|
@@ -180,6 +204,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
180
204
|
) : null,
|
|
181
205
|
header: props.localization?.select,
|
|
182
206
|
id: 'mrt-select',
|
|
207
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
208
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
183
209
|
size: 50,
|
|
184
210
|
}),
|
|
185
211
|
props.enableRowNumbers &&
|
|
@@ -188,6 +214,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
188
214
|
Header: () => props.localization?.rowNumber,
|
|
189
215
|
header: props.localization?.rowNumbers,
|
|
190
216
|
id: 'mrt-row-numbers',
|
|
217
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
|
218
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
191
219
|
size: 50,
|
|
192
220
|
}),
|
|
193
221
|
].filter(Boolean),
|
|
@@ -238,24 +266,14 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
238
266
|
|
|
239
267
|
//@ts-ignore
|
|
240
268
|
const tableInstance = {
|
|
269
|
+
//@ts-ignore
|
|
241
270
|
...useTableInstance(table, {
|
|
242
|
-
filterFns: defaultFilterFNs,
|
|
243
|
-
getCoreRowModel: getCoreRowModel(),
|
|
244
|
-
getExpandedRowModel: getExpandedRowModel(),
|
|
245
|
-
getFacetedRowModel: getFacetedRowModel(),
|
|
246
|
-
getFilteredRowModel: getFilteredRowModel(),
|
|
247
|
-
getGroupedRowModel: getGroupedRowModel(),
|
|
248
|
-
getPaginationRowModel: getPaginationRowModel(),
|
|
249
|
-
getSortedRowModel: getSortedRowModel(),
|
|
250
|
-
getSubRows: (row) => (row as MRT_Row)?.subRows,
|
|
251
|
-
//@ts-ignore
|
|
252
|
-
globalFilterFn: currentGlobalFilterFn,
|
|
253
271
|
...props,
|
|
254
272
|
//@ts-ignore
|
|
255
273
|
columns,
|
|
256
274
|
data,
|
|
257
|
-
|
|
258
|
-
|
|
275
|
+
//@ts-ignore
|
|
276
|
+
globalFilterFn: currentGlobalFilterFn,
|
|
259
277
|
state: {
|
|
260
278
|
currentEditingCell,
|
|
261
279
|
currentEditingRow,
|
package/src/utils.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
ColumnDef,
|
|
3
|
+
ColumnOrderState,
|
|
4
|
+
Table,
|
|
5
|
+
Updater,
|
|
6
|
+
} from '@tanstack/react-table';
|
|
7
|
+
import { MRT_Column, MRT_ColumnDef, MRT_FilterFn, } from '.';
|
|
3
8
|
import { MRT_FILTER_OPTION } from './enums';
|
|
4
9
|
import { defaultFilterFNs } from './filtersFNs';
|
|
5
10
|
|
|
@@ -52,3 +57,20 @@ export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
|
52
57
|
table: Table<D>,
|
|
53
58
|
column: Omit<MRT_ColumnDef<D>, 'header'> & { header?: string },
|
|
54
59
|
): ColumnDef<D> => table.createDisplayColumn(column as ColumnDef<D>);
|
|
60
|
+
|
|
61
|
+
export const reorderColumn = (
|
|
62
|
+
movingColumn: MRT_Column,
|
|
63
|
+
receivingColumn: MRT_Column,
|
|
64
|
+
columnOrder: ColumnOrderState,
|
|
65
|
+
setColumnOrder: (updater: Updater<ColumnOrderState>) => void,
|
|
66
|
+
) => {
|
|
67
|
+
if (movingColumn.getCanPin()) {
|
|
68
|
+
movingColumn.pin(receivingColumn.getIsPinned());
|
|
69
|
+
}
|
|
70
|
+
columnOrder.splice(
|
|
71
|
+
columnOrder.indexOf(receivingColumn.id),
|
|
72
|
+
0,
|
|
73
|
+
columnOrder.splice(columnOrder.indexOf(movingColumn.id), 1)[0],
|
|
74
|
+
);
|
|
75
|
+
setColumnOrder([...columnOrder]);
|
|
76
|
+
};
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { FC, Ref } from 'react';
|
|
2
|
-
import { MRT_Header, MRT_TableInstance } from '..';
|
|
3
|
-
interface Props {
|
|
4
|
-
header: MRT_Header;
|
|
5
|
-
ref: Ref<HTMLButtonElement>;
|
|
6
|
-
tableInstance: MRT_TableInstance;
|
|
7
|
-
}
|
|
8
|
-
export declare const MRT_TableHeadCellGrabHandle: FC<Props>;
|
|
9
|
-
export {};
|