material-react-table 0.18.0 → 0.19.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/MaterialReactTable.d.ts +169 -133
- package/dist/body/MRT_TableBody.d.ts +1 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -1
- package/dist/body/MRT_TableBodyRow.d.ts +1 -1
- package/dist/body/MRT_TableDetailPanel.d.ts +1 -1
- package/dist/buttons/MRT_ColumnPinningButtons.d.ts +1 -1
- package/dist/buttons/MRT_CopyButton.d.ts +1 -1
- package/dist/buttons/MRT_EditActionButtons.d.ts +1 -1
- package/dist/buttons/MRT_ExpandAllButton.d.ts +1 -1
- package/dist/buttons/MRT_ExpandButton.d.ts +1 -1
- package/dist/buttons/MRT_FullScreenToggleButton.d.ts +1 -1
- package/dist/buttons/MRT_GrabHandleButton.d.ts +1 -1
- package/dist/buttons/MRT_ShowHideColumnsButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleDensePaddingButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleFiltersButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleGlobalFilterButton.d.ts +1 -1
- package/dist/buttons/MRT_ToggleRowActionMenuButton.d.ts +1 -1
- package/dist/filtersFns.d.ts +31 -23
- package/dist/footer/MRT_TableFooter.d.ts +1 -1
- package/dist/footer/MRT_TableFooterCell.d.ts +1 -1
- package/dist/footer/MRT_TableFooterRow.d.ts +1 -1
- package/dist/head/MRT_DraggableTableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHead.d.ts +1 -1
- package/dist/head/MRT_TableHeadCell.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellColumnActionsButton.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellFilterContainer.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellFilterLabel.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellResizeHandle.d.ts +1 -1
- package/dist/head/MRT_TableHeadCellSortLabel.d.ts +1 -1
- package/dist/head/MRT_TableHeadRow.d.ts +1 -1
- package/dist/inputs/MRT_EditCellTextField.d.ts +1 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +1 -1
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -1
- package/dist/inputs/MRT_GlobalFilterTextField.d.ts +1 -1
- package/dist/inputs/MRT_SelectCheckbox.d.ts +1 -1
- package/dist/material-react-table.cjs.development.js +760 -759
- 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 +762 -761
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/MRT_ColumnActionMenu.d.ts +1 -1
- package/dist/menus/MRT_FilterOptionMenu.d.ts +1 -1
- package/dist/menus/MRT_RowActionMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenu.d.ts +1 -1
- package/dist/menus/MRT_ShowHideColumnsMenuItems.d.ts +1 -1
- package/dist/sortingFns.d.ts +10 -3
- package/dist/table/MRT_Table.d.ts +1 -1
- package/dist/table/MRT_TableContainer.d.ts +1 -1
- package/dist/table/MRT_TablePaper.d.ts +1 -1
- package/dist/toolbar/MRT_LinearProgressBar.d.ts +1 -1
- package/dist/toolbar/MRT_TablePagination.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarAlertBanner.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarBottom.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarInternalButtons.d.ts +1 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -1
- package/dist/utils.d.ts +10 -16
- package/package.json +4 -4
- package/src/MaterialReactTable.tsx +167 -156
- package/src/body/MRT_TableBody.tsx +5 -6
- package/src/body/MRT_TableBodyCell.tsx +18 -27
- package/src/body/MRT_TableBodyRow.tsx +7 -7
- package/src/body/MRT_TableDetailPanel.tsx +7 -7
- package/src/buttons/MRT_ColumnPinningButtons.tsx +3 -3
- package/src/buttons/MRT_CopyButton.tsx +5 -7
- package/src/buttons/MRT_EditActionButtons.tsx +4 -5
- package/src/buttons/MRT_ExpandAllButton.tsx +4 -5
- package/src/buttons/MRT_ExpandButton.tsx +4 -5
- package/src/buttons/MRT_FullScreenToggleButton.tsx +3 -7
- package/src/buttons/MRT_GrabHandleButton.tsx +39 -41
- package/src/buttons/MRT_ShowHideColumnsButton.tsx +4 -4
- package/src/buttons/MRT_ToggleDensePaddingButton.tsx +3 -7
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -4
- package/src/buttons/MRT_ToggleGlobalFilterButton.tsx +4 -8
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +6 -6
- package/src/filtersFns.ts +24 -23
- package/src/footer/MRT_TableFooter.tsx +5 -6
- package/src/footer/MRT_TableFooterCell.tsx +8 -11
- package/src/footer/MRT_TableFooterRow.tsx +5 -9
- package/src/head/MRT_DraggableTableHeadCell.tsx +4 -6
- package/src/head/MRT_TableHead.tsx +5 -5
- package/src/head/MRT_TableHeadCell.tsx +18 -29
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +6 -8
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +5 -7
- package/src/head/MRT_TableHeadCellFilterLabel.tsx +13 -19
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +12 -11
- package/src/head/MRT_TableHeadCellSortLabel.tsx +3 -5
- package/src/head/MRT_TableHeadRow.tsx +6 -6
- package/src/inputs/MRT_EditCellTextField.tsx +12 -14
- package/src/inputs/MRT_FilterRangeFields.tsx +4 -4
- package/src/inputs/MRT_FilterTextField.tsx +27 -38
- package/src/inputs/MRT_GlobalFilterTextField.tsx +5 -6
- package/src/inputs/MRT_SelectCheckbox.tsx +9 -12
- package/src/menus/MRT_ColumnActionMenu.tsx +5 -9
- package/src/menus/MRT_FilterOptionMenu.tsx +16 -48
- package/src/menus/MRT_RowActionMenu.tsx +4 -5
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +8 -9
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +11 -10
- package/src/sortingFns.ts +11 -3
- package/src/table/MRT_Table.tsx +7 -11
- package/src/table/MRT_TableContainer.tsx +5 -6
- package/src/table/MRT_TablePaper.tsx +7 -8
- package/src/table/MRT_TableRoot.tsx +118 -132
- package/src/toolbar/MRT_LinearProgressBar.tsx +4 -5
- package/src/toolbar/MRT_TablePagination.tsx +7 -9
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +13 -9
- package/src/toolbar/MRT_ToolbarBottom.tsx +8 -9
- package/src/toolbar/MRT_ToolbarInternalButtons.tsx +10 -10
- package/src/toolbar/MRT_ToolbarTop.tsx +11 -11
- package/src/utils.ts +56 -50
@@ -17,14 +17,14 @@ interface Props {
|
|
17
17
|
allColumns: MRT_Column[];
|
18
18
|
column: MRT_Column;
|
19
19
|
isSubMenu?: boolean;
|
20
|
-
|
20
|
+
table: MRT_TableInstance;
|
21
21
|
}
|
22
22
|
|
23
23
|
export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
24
24
|
allColumns,
|
25
25
|
column,
|
26
26
|
isSubMenu,
|
27
|
-
|
27
|
+
table,
|
28
28
|
}) => {
|
29
29
|
const {
|
30
30
|
getState,
|
@@ -35,11 +35,10 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
35
35
|
localization,
|
36
36
|
},
|
37
37
|
setColumnOrder,
|
38
|
-
} =
|
39
|
-
|
38
|
+
} = table;
|
40
39
|
const { columnOrder } = getState();
|
41
|
-
|
42
|
-
const {
|
40
|
+
const { columnDef } = column;
|
41
|
+
const { columnDefType } = columnDef;
|
43
42
|
|
44
43
|
const [, dropRef] = useDrop({
|
45
44
|
accept: 'column',
|
@@ -94,11 +93,13 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
94
93
|
>
|
95
94
|
{columnDefType !== 'group' &&
|
96
95
|
enableColumnOrdering &&
|
97
|
-
!allColumns.some(
|
96
|
+
!allColumns.some(
|
97
|
+
(col) => col.columnDef.columnDefType === 'group',
|
98
|
+
) &&
|
98
99
|
(columnDef.enableColumnOrdering !== false ? (
|
99
100
|
<MRT_GrabHandleButton
|
100
101
|
ref={dragRef as Ref<HTMLButtonElement>}
|
101
|
-
|
102
|
+
table={table}
|
102
103
|
/>
|
103
104
|
) : (
|
104
105
|
<Box sx={{ width: '28px' }} />
|
@@ -106,7 +107,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
106
107
|
{enablePinning &&
|
107
108
|
!isSubMenu &&
|
108
109
|
(column.getCanPin() ? (
|
109
|
-
<MRT_ColumnPinningButtons column={column}
|
110
|
+
<MRT_ColumnPinningButtons column={column} table={table} />
|
110
111
|
) : (
|
111
112
|
<Box sx={{ width: '70px' }} />
|
112
113
|
))}
|
@@ -152,7 +153,7 @@ export const MRT_ShowHideColumnsMenuItems: FC<Props> = ({
|
|
152
153
|
key={`${i}-${c.id}`}
|
153
154
|
column={c}
|
154
155
|
isSubMenu={isSubMenu}
|
155
|
-
|
156
|
+
table={table}
|
156
157
|
/>
|
157
158
|
))}
|
158
159
|
</>
|
package/src/sortingFns.ts
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
|
2
2
|
import { Row, sortingFns } from '@tanstack/react-table';
|
3
|
-
import
|
3
|
+
import { MRT_Row } from '.';
|
4
4
|
|
5
|
-
const fuzzy =
|
5
|
+
const fuzzy = <D extends Record<string, any> = {}>(
|
6
|
+
rowA: Row<D>,
|
7
|
+
rowB: Row<D>,
|
8
|
+
columnId: string,
|
9
|
+
) => {
|
6
10
|
let dir = 0;
|
7
11
|
if (rowA.columnFiltersMeta[columnId]) {
|
8
12
|
dir = compareItems(
|
@@ -17,9 +21,13 @@ const fuzzy = (rowA: MRT_Row, rowB: MRT_Row, columnId: string) => {
|
|
17
21
|
};
|
18
22
|
|
19
23
|
export const MRT_SortingFns = {
|
24
|
+
...sortingFns,
|
20
25
|
fuzzy,
|
21
26
|
};
|
22
27
|
|
23
|
-
export const rankGlobalFuzzy =
|
28
|
+
export const rankGlobalFuzzy = <D extends Record<string, any> = {}>(
|
29
|
+
rowA: MRT_Row<D>,
|
30
|
+
rowB: MRT_Row<D>,
|
31
|
+
) =>
|
24
32
|
Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
|
25
33
|
Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
|
package/src/table/MRT_Table.tsx
CHANGED
@@ -7,10 +7,10 @@ import { MRT_TableInstance } from '..';
|
|
7
7
|
|
8
8
|
interface Props {
|
9
9
|
tableContainerRef: RefObject<HTMLDivElement>;
|
10
|
-
|
10
|
+
table: MRT_TableInstance;
|
11
11
|
}
|
12
12
|
|
13
|
-
export const MRT_Table: FC<Props> = ({ tableContainerRef,
|
13
|
+
export const MRT_Table: FC<Props> = ({ tableContainerRef, table }) => {
|
14
14
|
const {
|
15
15
|
getState,
|
16
16
|
options: {
|
@@ -21,13 +21,12 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, instance }) => {
|
|
21
21
|
enableTableHead,
|
22
22
|
muiTableProps,
|
23
23
|
},
|
24
|
-
} =
|
25
|
-
|
24
|
+
} = table;
|
26
25
|
const { isFullScreen } = getState();
|
27
26
|
|
28
27
|
const tableProps =
|
29
28
|
muiTableProps instanceof Function
|
30
|
-
? muiTableProps({
|
29
|
+
? muiTableProps({ table })
|
31
30
|
: muiTableProps;
|
32
31
|
|
33
32
|
return (
|
@@ -42,12 +41,9 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, instance }) => {
|
|
42
41
|
...tableProps?.sx,
|
43
42
|
}}
|
44
43
|
>
|
45
|
-
{enableTableHead && <MRT_TableHead
|
46
|
-
<MRT_TableBody
|
47
|
-
|
48
|
-
instance={instance}
|
49
|
-
/>
|
50
|
-
{enableTableFooter && <MRT_TableFooter instance={instance} />}
|
44
|
+
{enableTableHead && <MRT_TableHead table={table} />}
|
45
|
+
<MRT_TableBody tableContainerRef={tableContainerRef} table={table} />
|
46
|
+
{enableTableFooter && <MRT_TableFooter table={table} />}
|
51
47
|
</Table>
|
52
48
|
);
|
53
49
|
};
|
@@ -7,10 +7,10 @@ const useIsomorphicLayoutEffect =
|
|
7
7
|
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
8
8
|
|
9
9
|
interface Props {
|
10
|
-
|
10
|
+
table: MRT_TableInstance;
|
11
11
|
}
|
12
12
|
|
13
|
-
export const MRT_TableContainer: FC<Props> = ({
|
13
|
+
export const MRT_TableContainer: FC<Props> = ({ table }) => {
|
14
14
|
const {
|
15
15
|
getState,
|
16
16
|
options: {
|
@@ -19,15 +19,14 @@ export const MRT_TableContainer: FC<Props> = ({ instance }) => {
|
|
19
19
|
muiTableContainerProps,
|
20
20
|
tableId,
|
21
21
|
},
|
22
|
-
} =
|
23
|
-
|
22
|
+
} = table;
|
24
23
|
const { isFullScreen } = getState();
|
25
24
|
|
26
25
|
const [totalToolbarHeight, setTotalToolbarHeight] = useState(0);
|
27
26
|
|
28
27
|
const tableContainerProps =
|
29
28
|
muiTableContainerProps instanceof Function
|
30
|
-
? muiTableContainerProps({
|
29
|
+
? muiTableContainerProps({ table })
|
31
30
|
: muiTableContainerProps;
|
32
31
|
|
33
32
|
useIsomorphicLayoutEffect(() => {
|
@@ -68,7 +67,7 @@ export const MRT_TableContainer: FC<Props> = ({ instance }) => {
|
|
68
67
|
...tableContainerProps?.style,
|
69
68
|
}}
|
70
69
|
>
|
71
|
-
<MRT_Table tableContainerRef={tableContainerRef}
|
70
|
+
<MRT_Table tableContainerRef={tableContainerRef} table={table} />
|
72
71
|
</TableContainer>
|
73
72
|
);
|
74
73
|
};
|
@@ -8,15 +8,14 @@ import { MRT_TableContainer } from './MRT_TableContainer';
|
|
8
8
|
import type { MRT_TableInstance } from '..';
|
9
9
|
|
10
10
|
interface Props {
|
11
|
-
|
11
|
+
table: MRT_TableInstance;
|
12
12
|
}
|
13
13
|
|
14
|
-
export const MRT_TablePaper: FC<Props> = ({
|
14
|
+
export const MRT_TablePaper: FC<Props> = ({ table }) => {
|
15
15
|
const {
|
16
16
|
getState,
|
17
17
|
options: { enableToolbarBottom, enableToolbarTop, muiTablePaperProps },
|
18
|
-
} =
|
19
|
-
|
18
|
+
} = table;
|
20
19
|
const { isFullScreen } = getState();
|
21
20
|
|
22
21
|
useEffect(() => {
|
@@ -31,7 +30,7 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
|
|
31
30
|
|
32
31
|
const tablePaperProps =
|
33
32
|
muiTablePaperProps instanceof Function
|
34
|
-
? muiTablePaperProps({
|
33
|
+
? muiTablePaperProps({ table })
|
35
34
|
: muiTablePaperProps;
|
36
35
|
|
37
36
|
return (
|
@@ -53,9 +52,9 @@ export const MRT_TablePaper: FC<Props> = ({ instance }) => {
|
|
53
52
|
width: isFullScreen ? '100vw' : undefined,
|
54
53
|
}}
|
55
54
|
>
|
56
|
-
{enableToolbarTop && <MRT_ToolbarTop
|
57
|
-
<MRT_TableContainer
|
58
|
-
{enableToolbarBottom && <MRT_ToolbarBottom
|
55
|
+
{enableToolbarTop && <MRT_ToolbarTop table={table} />}
|
56
|
+
<MRT_TableContainer table={table} />
|
57
|
+
{enableToolbarBottom && <MRT_ToolbarBottom table={table} />}
|
59
58
|
</Paper>
|
60
59
|
</DndProvider>
|
61
60
|
);
|
@@ -1,11 +1,6 @@
|
|
1
1
|
import React, { useEffect, useMemo, useState } from 'react';
|
2
2
|
import {
|
3
|
-
FilterFn,
|
4
|
-
ReactTableGenerics,
|
5
|
-
Table,
|
6
3
|
TableState,
|
7
|
-
createTable,
|
8
|
-
filterFns,
|
9
4
|
getCoreRowModel,
|
10
5
|
getExpandedRowModel,
|
11
6
|
getFacetedRowModel,
|
@@ -13,14 +8,12 @@ import {
|
|
13
8
|
getGroupedRowModel,
|
14
9
|
getPaginationRowModel,
|
15
10
|
getSortedRowModel,
|
16
|
-
|
17
|
-
sortingFns,
|
11
|
+
useReactTable,
|
18
12
|
} from '@tanstack/react-table';
|
19
13
|
import {
|
20
14
|
MRT_Cell,
|
21
15
|
MRT_ColumnDef,
|
22
|
-
|
23
|
-
MRT_FILTER_OPTION,
|
16
|
+
MRT_FilterOption,
|
24
17
|
MRT_Row,
|
25
18
|
MRT_TableInstance,
|
26
19
|
MRT_TableState,
|
@@ -33,14 +26,11 @@ import { MaterialReactTableProps } from '../MaterialReactTable';
|
|
33
26
|
import { MRT_TablePaper } from './MRT_TablePaper';
|
34
27
|
import { Box, Dialog, Grow } from '@mui/material';
|
35
28
|
import {
|
36
|
-
|
37
|
-
createDisplayColumn,
|
38
|
-
createGroup,
|
29
|
+
prepareColumns,
|
39
30
|
getAllLeafColumnDefs,
|
40
31
|
getDefaultColumnOrderIds,
|
41
32
|
} from '../utils';
|
42
33
|
import { MRT_FilterFns } from '../filtersFns';
|
43
|
-
import { MRT_SortingFns } from '../sortingFns';
|
44
34
|
|
45
35
|
export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
46
36
|
props: MaterialReactTableProps<D>,
|
@@ -84,125 +74,114 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
84
74
|
);
|
85
75
|
|
86
76
|
const [currentFilterFns, setCurrentFilterFns] = useState<{
|
87
|
-
[key: string]:
|
77
|
+
[key: string]: MRT_FilterOption;
|
88
78
|
}>(() =>
|
89
79
|
Object.assign(
|
90
80
|
{},
|
91
|
-
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
81
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<D>[]).map(
|
82
|
+
(col) => ({
|
83
|
+
[col.id?.toString() ?? col.accessorKey?.toString() ?? '']:
|
84
|
+
col.filterFn instanceof Function
|
85
|
+
? col.filterFn.name ?? 'custom'
|
86
|
+
: col.filterFn ??
|
87
|
+
initialState?.currentFilterFns?.[
|
88
|
+
col.id?.toString() ?? col.accessorKey?.toString() ?? ''
|
89
|
+
] ??
|
90
|
+
(!!col.filterSelectOptions?.length ? 'equals' : 'fuzzy'),
|
91
|
+
}),
|
92
|
+
),
|
97
93
|
),
|
98
94
|
);
|
99
95
|
|
100
|
-
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] =
|
101
|
-
|
102
|
-
|
96
|
+
const [currentGlobalFilterFn, setCurrentGlobalFilterFn] =
|
97
|
+
useState<MRT_FilterOption>(
|
98
|
+
props.globalFilterFn instanceof String
|
99
|
+
? (props.globalFilterFn as MRT_FilterOption)
|
100
|
+
: 'fuzzy',
|
101
|
+
);
|
103
102
|
|
104
|
-
const
|
103
|
+
const displayColumns = useMemo(
|
105
104
|
() =>
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
105
|
+
(
|
106
|
+
[
|
107
|
+
columnOrder.includes('mrt-row-actions') && {
|
108
|
+
Cell: ({ cell }) => (
|
109
|
+
<MRT_ToggleRowActionMenuButton
|
110
|
+
row={cell.row as any}
|
111
|
+
table={table}
|
112
|
+
/>
|
113
|
+
),
|
114
|
+
columnDefType: 'display',
|
115
|
+
header: props.localization?.actions,
|
116
|
+
id: 'mrt-row-actions',
|
117
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
118
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
119
|
+
size: 70,
|
120
|
+
},
|
121
|
+
columnOrder.includes('mrt-expand') && {
|
122
|
+
Cell: ({ cell }) => (
|
123
|
+
<MRT_ExpandButton row={cell.row as any} table={table} />
|
124
|
+
),
|
125
|
+
Header: () =>
|
126
|
+
props.enableExpandAll ? (
|
127
|
+
<MRT_ExpandAllButton table={table} />
|
128
|
+
) : null,
|
129
|
+
columnDefType: 'display',
|
130
|
+
header: props.localization?.expand,
|
131
|
+
id: 'mrt-expand',
|
132
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
133
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
134
|
+
size: 60,
|
135
|
+
},
|
136
|
+
columnOrder.includes('mrt-select') && {
|
137
|
+
Cell: ({ cell }) => (
|
138
|
+
<MRT_SelectCheckbox row={cell.row as any} table={table} />
|
139
|
+
),
|
140
|
+
Header: () =>
|
141
|
+
props.enableSelectAll ? (
|
142
|
+
<MRT_SelectCheckbox selectAll table={table} />
|
143
|
+
) : null,
|
144
|
+
columnDefType: 'display',
|
145
|
+
header: props.localization?.select,
|
146
|
+
id: 'mrt-select',
|
147
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
148
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
149
|
+
size: 60,
|
150
|
+
},
|
151
|
+
columnOrder.includes('mrt-row-numbers') && {
|
152
|
+
Cell: ({ cell }) => cell.row.index + 1,
|
153
|
+
Header: () => props.localization?.rowNumber,
|
154
|
+
columnDefType: 'display',
|
155
|
+
header: props.localization?.rowNumbers,
|
156
|
+
id: 'mrt-row-numbers',
|
157
|
+
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
158
|
+
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
159
|
+
size: 60,
|
160
|
+
},
|
161
|
+
] as MRT_ColumnDef<D>[]
|
162
|
+
).filter(Boolean),
|
163
|
+
[
|
164
|
+
columnOrder,
|
165
|
+
props.editingMode,
|
166
|
+
props.enableEditing,
|
167
|
+
props.enableExpandAll,
|
168
|
+
props.enableExpanding,
|
169
|
+
props.enableGrouping,
|
170
|
+
props.enableRowActions,
|
171
|
+
props.enableRowNumbers,
|
172
|
+
props.enableRowSelection,
|
173
|
+
props.enableSelectAll,
|
174
|
+
props.localization,
|
175
|
+
props.muiTableBodyCellProps,
|
176
|
+
props.muiTableHeadCellProps,
|
177
|
+
props.positionActionsColumn,
|
178
|
+
],
|
119
179
|
);
|
120
180
|
|
121
|
-
const
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
Cell: ({ cell }) => (
|
126
|
-
<MRT_ToggleRowActionMenuButton
|
127
|
-
row={cell.row as any}
|
128
|
-
instance={instance}
|
129
|
-
/>
|
130
|
-
),
|
131
|
-
header: props.localization?.actions,
|
132
|
-
id: 'mrt-row-actions',
|
133
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
134
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
135
|
-
size: 70,
|
136
|
-
}),
|
137
|
-
columnOrder.includes('mrt-expand') &&
|
138
|
-
createDisplayColumn(table, {
|
139
|
-
Cell: ({ cell }) => (
|
140
|
-
<MRT_ExpandButton row={cell.row as any} instance={instance} />
|
141
|
-
),
|
142
|
-
Header: () =>
|
143
|
-
props.enableExpandAll ? (
|
144
|
-
<MRT_ExpandAllButton instance={instance} />
|
145
|
-
) : null,
|
146
|
-
header: props.localization?.expand,
|
147
|
-
id: 'mrt-expand',
|
148
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
149
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
150
|
-
size: 60,
|
151
|
-
}),
|
152
|
-
columnOrder.includes('mrt-select') &&
|
153
|
-
createDisplayColumn(table, {
|
154
|
-
Cell: ({ cell }) => (
|
155
|
-
<MRT_SelectCheckbox row={cell.row as any} instance={instance} />
|
156
|
-
),
|
157
|
-
Header: () =>
|
158
|
-
props.enableSelectAll ? (
|
159
|
-
<MRT_SelectCheckbox selectAll instance={instance} />
|
160
|
-
) : null,
|
161
|
-
header: props.localization?.select,
|
162
|
-
id: 'mrt-select',
|
163
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
164
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
165
|
-
size: 60,
|
166
|
-
}),
|
167
|
-
columnOrder.includes('mrt-row-numbers') &&
|
168
|
-
createDisplayColumn(table, {
|
169
|
-
Cell: ({ cell }) => cell.row.index + 1,
|
170
|
-
Header: () => props.localization?.rowNumber,
|
171
|
-
header: props.localization?.rowNumbers,
|
172
|
-
id: 'mrt-row-numbers',
|
173
|
-
muiTableBodyCellProps: props.muiTableBodyCellProps,
|
174
|
-
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
175
|
-
size: 60,
|
176
|
-
}),
|
177
|
-
].filter(Boolean) as MRT_ColumnDef<D>[];
|
178
|
-
}, [
|
179
|
-
columnOrder,
|
180
|
-
props.editingMode,
|
181
|
-
props.enableEditing,
|
182
|
-
props.enableExpandAll,
|
183
|
-
props.enableExpanding,
|
184
|
-
props.enableGrouping,
|
185
|
-
props.enableRowActions,
|
186
|
-
props.enableRowNumbers,
|
187
|
-
props.enableRowSelection,
|
188
|
-
props.enableSelectAll,
|
189
|
-
props.localization,
|
190
|
-
props.muiTableBodyCellProps,
|
191
|
-
props.muiTableHeadCellProps,
|
192
|
-
props.positionActionsColumn,
|
193
|
-
table,
|
194
|
-
]);
|
195
|
-
|
196
|
-
const columns = useMemo(
|
197
|
-
() => [
|
198
|
-
...displayColumns,
|
199
|
-
...props.columns.map((column) =>
|
200
|
-
column.columns
|
201
|
-
? createGroup(table, column as any, currentFilterFns)
|
202
|
-
: createDataColumn(table, column as any, currentFilterFns),
|
203
|
-
),
|
204
|
-
],
|
205
|
-
[table, props.columns, currentFilterFns],
|
181
|
+
const columnDefs = useMemo(
|
182
|
+
() =>
|
183
|
+
prepareColumns([...displayColumns, ...props.columns], currentFilterFns),
|
184
|
+
[currentFilterFns, displayColumns, props.columns],
|
206
185
|
);
|
207
186
|
|
208
187
|
const data: D[] = useMemo(
|
@@ -213,8 +192,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
213
192
|
Object.assign(
|
214
193
|
{},
|
215
194
|
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef[]).map(
|
216
|
-
(
|
217
|
-
[
|
195
|
+
(col) => ({
|
196
|
+
[col.id ?? col.accessorKey ?? '']: null,
|
218
197
|
}),
|
219
198
|
),
|
220
199
|
),
|
@@ -224,17 +203,24 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
224
203
|
);
|
225
204
|
|
226
205
|
//@ts-ignore
|
227
|
-
const
|
228
|
-
|
229
|
-
|
206
|
+
const table = {
|
207
|
+
...useReactTable({
|
208
|
+
getCoreRowModel: getCoreRowModel(),
|
209
|
+
getExpandedRowModel: getExpandedRowModel(),
|
210
|
+
getFacetedRowModel: getFacetedRowModel(),
|
211
|
+
getFilteredRowModel: getFilteredRowModel(),
|
212
|
+
getGroupedRowModel: getGroupedRowModel(),
|
213
|
+
getPaginationRowModel: getPaginationRowModel(),
|
214
|
+
getSortedRowModel: getSortedRowModel(),
|
230
215
|
onColumnOrderChange: setColumnOrder,
|
231
216
|
...props,
|
232
217
|
//@ts-ignore
|
233
|
-
columns,
|
218
|
+
columns: columnDefs,
|
234
219
|
data,
|
235
|
-
getSubRows: (row) =>
|
220
|
+
getSubRows: (row) => row?.subRows,
|
236
221
|
//@ts-ignore
|
237
|
-
globalFilterFn:
|
222
|
+
globalFilterFn:
|
223
|
+
MRT_FilterFns[currentGlobalFilterFn] ?? MRT_FilterFns.fuzzy,
|
238
224
|
initialState,
|
239
225
|
state: {
|
240
226
|
columnOrder,
|
@@ -277,9 +263,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
277
263
|
open={isFullScreen}
|
278
264
|
transitionDuration={400}
|
279
265
|
>
|
280
|
-
<MRT_TablePaper
|
266
|
+
<MRT_TablePaper table={table} />
|
281
267
|
</Dialog>
|
282
|
-
{!isFullScreen && <MRT_TablePaper
|
268
|
+
{!isFullScreen && <MRT_TablePaper table={table} />}
|
283
269
|
</>
|
284
270
|
);
|
285
271
|
};
|
@@ -4,20 +4,19 @@ import { MRT_TableInstance } from '..';
|
|
4
4
|
|
5
5
|
interface Props {
|
6
6
|
alignTo: 'bottom' | 'top';
|
7
|
-
|
7
|
+
table: MRT_TableInstance;
|
8
8
|
}
|
9
9
|
|
10
|
-
export const MRT_LinearProgressBar: FC<Props> = ({ alignTo,
|
10
|
+
export const MRT_LinearProgressBar: FC<Props> = ({ alignTo, table }) => {
|
11
11
|
const {
|
12
12
|
options: { muiLinearProgressProps },
|
13
13
|
getState,
|
14
|
-
} =
|
15
|
-
|
14
|
+
} = table;
|
16
15
|
const { isLoading, showProgressBars } = getState();
|
17
16
|
|
18
17
|
const linearProgressProps =
|
19
18
|
muiLinearProgressProps instanceof Function
|
20
|
-
? muiLinearProgressProps({
|
19
|
+
? muiLinearProgressProps({ table })
|
21
20
|
: muiLinearProgressProps;
|
22
21
|
|
23
22
|
return (
|
@@ -3,11 +3,11 @@ import { TablePagination } from '@mui/material';
|
|
3
3
|
import { MRT_TableInstance } from '..';
|
4
4
|
|
5
5
|
interface Props {
|
6
|
-
|
6
|
+
table: MRT_TableInstance;
|
7
7
|
position: 'top' | 'bottom';
|
8
8
|
}
|
9
9
|
|
10
|
-
export const MRT_TablePagination: FC<Props> = ({
|
10
|
+
export const MRT_TablePagination: FC<Props> = ({ table, position }) => {
|
11
11
|
const {
|
12
12
|
getPrePaginationRowModel,
|
13
13
|
getState,
|
@@ -18,26 +18,24 @@ export const MRT_TablePagination: FC<Props> = ({ instance, position }) => {
|
|
18
18
|
enableToolbarInternalActions,
|
19
19
|
rowCount,
|
20
20
|
},
|
21
|
-
} =
|
22
|
-
|
21
|
+
} = table;
|
23
22
|
const {
|
24
23
|
pagination: { pageSize = 10, pageIndex = 0 },
|
25
24
|
showGlobalFilter,
|
26
25
|
} = getState();
|
27
26
|
|
27
|
+
const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
|
28
|
+
const showFirstLastPageButtons = totalRowCount / pageSize > 2;
|
29
|
+
|
28
30
|
const tablePaginationProps =
|
29
31
|
muiTablePaginationProps instanceof Function
|
30
|
-
? muiTablePaginationProps({
|
32
|
+
? muiTablePaginationProps({ table })
|
31
33
|
: muiTablePaginationProps;
|
32
34
|
|
33
35
|
const handleChangeRowsPerPage = (event: ChangeEvent<HTMLInputElement>) => {
|
34
36
|
setPageSize(+event.target.value);
|
35
37
|
};
|
36
38
|
|
37
|
-
const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
|
38
|
-
|
39
|
-
const showFirstLastPageButtons = totalRowCount / pageSize > 2;
|
40
|
-
|
41
39
|
return (
|
42
40
|
<TablePagination
|
43
41
|
SelectProps={{
|
@@ -1,28 +1,27 @@
|
|
1
1
|
import React, { FC, Fragment } from 'react';
|
2
|
-
import { Alert, Box, Chip, Collapse } from '@mui/material';
|
2
|
+
import { Alert, AlertTitle, Box, Chip, Collapse } from '@mui/material';
|
3
3
|
import { MRT_TableInstance } from '..';
|
4
4
|
|
5
5
|
interface Props {
|
6
6
|
stackAlertBanner?: boolean;
|
7
|
-
|
7
|
+
table: MRT_TableInstance;
|
8
8
|
}
|
9
9
|
|
10
10
|
export const MRT_ToolbarAlertBanner: FC<Props> = ({
|
11
11
|
stackAlertBanner,
|
12
|
-
|
12
|
+
table,
|
13
13
|
}) => {
|
14
14
|
const {
|
15
15
|
getPrePaginationRowModel,
|
16
16
|
getSelectedRowModel,
|
17
17
|
getState,
|
18
18
|
options: { localization, muiTableToolbarAlertBannerProps },
|
19
|
-
} =
|
20
|
-
|
19
|
+
} = table;
|
21
20
|
const { grouping, showAlertBanner } = getState();
|
22
21
|
|
23
22
|
const alertProps =
|
24
23
|
muiTableToolbarAlertBannerProps instanceof Function
|
25
|
-
? muiTableToolbarAlertBannerProps({
|
24
|
+
? muiTableToolbarAlertBannerProps({ table })
|
26
25
|
: muiTableToolbarAlertBannerProps;
|
27
26
|
|
28
27
|
const selectMessage =
|
@@ -47,8 +46,8 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
|
|
47
46
|
{index > 0 ? localization.thenBy : ''}
|
48
47
|
<Chip
|
49
48
|
color="secondary"
|
50
|
-
label={
|
51
|
-
onDelete={() =>
|
49
|
+
label={table.getColumn(columnId).columnDef.header}
|
50
|
+
onDelete={() => table.getColumn(columnId).toggleGrouping()}
|
52
51
|
/>
|
53
52
|
</Fragment>
|
54
53
|
))}
|
@@ -63,6 +62,7 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
|
|
63
62
|
<Alert
|
64
63
|
color="info"
|
65
64
|
icon={false}
|
65
|
+
{...alertProps}
|
66
66
|
sx={{
|
67
67
|
borderRadius: 0,
|
68
68
|
fontSize: '1rem',
|
@@ -75,9 +75,13 @@ export const MRT_ToolbarAlertBanner: FC<Props> = ({
|
|
75
75
|
zIndex: 2,
|
76
76
|
...alertProps?.sx,
|
77
77
|
}}
|
78
|
-
{...alertProps}
|
79
78
|
>
|
79
|
+
{alertProps?.title && <AlertTitle>{alertProps.title}</AlertTitle>}
|
80
80
|
<Box sx={{ p: '0.5rem 1rem' }}>
|
81
|
+
{alertProps?.children}
|
82
|
+
{alertProps?.children && (selectMessage || groupedByMessage) && (
|
83
|
+
<br />
|
84
|
+
)}
|
81
85
|
{selectMessage}
|
82
86
|
{selectMessage && groupedByMessage && <br />}
|
83
87
|
{groupedByMessage}
|