material-react-table 0.18.1 → 0.20.0
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 +170 -135
- 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 +1161 -1104
- 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 +776 -765
- 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 +7 -7
- package/src/MaterialReactTable.tsx +169 -158
- package/src/body/MRT_TableBody.tsx +26 -19
- 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 +6 -7
- 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
|
@@ -4,25 +4,24 @@ 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
|
))}
|
|
@@ -7,10 +7,10 @@ import { commonToolbarStyles } from './MRT_ToolbarTop';
|
|
|
7
7
|
import { MRT_TableInstance } from '..';
|
|
8
8
|
|
|
9
9
|
interface Props {
|
|
10
|
-
|
|
10
|
+
table: MRT_TableInstance;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
export const MRT_ToolbarBottom: FC<Props> = ({
|
|
13
|
+
export const MRT_ToolbarBottom: FC<Props> = ({ table }) => {
|
|
14
14
|
const {
|
|
15
15
|
getState,
|
|
16
16
|
options: {
|
|
@@ -21,15 +21,14 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
21
21
|
renderToolbarBottomCustomActions,
|
|
22
22
|
tableId,
|
|
23
23
|
},
|
|
24
|
-
} =
|
|
25
|
-
|
|
24
|
+
} = table;
|
|
26
25
|
const { isFullScreen } = getState();
|
|
27
26
|
|
|
28
27
|
const isMobile = useMediaQuery('(max-width:720px)');
|
|
29
28
|
|
|
30
29
|
const toolbarProps =
|
|
31
30
|
muiTableToolbarBottomProps instanceof Function
|
|
32
|
-
? muiTableToolbarBottomProps({
|
|
31
|
+
? muiTableToolbarBottomProps({ table })
|
|
33
32
|
: muiTableToolbarBottomProps;
|
|
34
33
|
|
|
35
34
|
const stackAlertBanner =
|
|
@@ -54,9 +53,9 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
54
53
|
} as any)
|
|
55
54
|
}
|
|
56
55
|
>
|
|
57
|
-
<MRT_LinearProgressBar alignTo="top"
|
|
56
|
+
<MRT_LinearProgressBar alignTo="top" table={table} />
|
|
58
57
|
{positionToolbarAlertBanner === 'bottom' && (
|
|
59
|
-
<MRT_ToolbarAlertBanner
|
|
58
|
+
<MRT_ToolbarAlertBanner table={table} />
|
|
60
59
|
)}
|
|
61
60
|
<Box
|
|
62
61
|
sx={{
|
|
@@ -67,7 +66,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
67
66
|
>
|
|
68
67
|
{renderToolbarBottomCustomActions ? (
|
|
69
68
|
<Box sx={{ p: '0.5rem' }}>
|
|
70
|
-
{renderToolbarBottomCustomActions({
|
|
69
|
+
{renderToolbarBottomCustomActions({ table })}
|
|
71
70
|
</Box>
|
|
72
71
|
) : (
|
|
73
72
|
<span />
|
|
@@ -83,7 +82,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ instance }) => {
|
|
|
83
82
|
>
|
|
84
83
|
{enablePagination &&
|
|
85
84
|
['bottom', 'both'].includes(positionPagination ?? '') && (
|
|
86
|
-
<MRT_TablePagination
|
|
85
|
+
<MRT_TablePagination table={table} position="bottom" />
|
|
87
86
|
)}
|
|
88
87
|
</Box>
|
|
89
88
|
</Box>
|
|
@@ -9,10 +9,10 @@ import { MRT_TableInstance } from '..';
|
|
|
9
9
|
import { MRT_GlobalFilterTextField } from '../inputs/MRT_GlobalFilterTextField';
|
|
10
10
|
|
|
11
11
|
interface Props {
|
|
12
|
-
|
|
12
|
+
table: MRT_TableInstance;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export const MRT_ToolbarInternalButtons: FC<Props> = ({
|
|
15
|
+
export const MRT_ToolbarInternalButtons: FC<Props> = ({ table }) => {
|
|
16
16
|
const {
|
|
17
17
|
options: {
|
|
18
18
|
enableColumnFilters,
|
|
@@ -26,7 +26,7 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
|
|
|
26
26
|
positionGlobalFilter,
|
|
27
27
|
renderToolbarInternalActions,
|
|
28
28
|
},
|
|
29
|
-
} =
|
|
29
|
+
} = table;
|
|
30
30
|
|
|
31
31
|
return (
|
|
32
32
|
<Box
|
|
@@ -42,26 +42,26 @@ export const MRT_ToolbarInternalButtons: FC<Props> = ({ instance }) => {
|
|
|
42
42
|
MRT_ToggleDensePaddingButton,
|
|
43
43
|
MRT_ToggleFiltersButton,
|
|
44
44
|
MRT_ToggleGlobalFilterButton,
|
|
45
|
-
|
|
45
|
+
table,
|
|
46
46
|
}) ?? (
|
|
47
47
|
<>
|
|
48
48
|
{enableGlobalFilter && positionGlobalFilter === 'right' && (
|
|
49
|
-
<MRT_GlobalFilterTextField
|
|
49
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
50
50
|
)}
|
|
51
51
|
{enableFilters && enableGlobalFilter && (
|
|
52
|
-
<MRT_ToggleGlobalFilterButton
|
|
52
|
+
<MRT_ToggleGlobalFilterButton table={table} />
|
|
53
53
|
)}
|
|
54
54
|
{enableFilters && enableColumnFilters && (
|
|
55
|
-
<MRT_ToggleFiltersButton
|
|
55
|
+
<MRT_ToggleFiltersButton table={table} />
|
|
56
56
|
)}
|
|
57
57
|
{(enableHiding || enableColumnOrdering || enablePinning) && (
|
|
58
|
-
<MRT_ShowHideColumnsButton
|
|
58
|
+
<MRT_ShowHideColumnsButton table={table} />
|
|
59
59
|
)}
|
|
60
60
|
{enableDensityToggle && (
|
|
61
|
-
<MRT_ToggleDensePaddingButton
|
|
61
|
+
<MRT_ToggleDensePaddingButton table={table} />
|
|
62
62
|
)}
|
|
63
63
|
{enableFullScreenToggle && (
|
|
64
|
-
<MRT_FullScreenToggleButton
|
|
64
|
+
<MRT_FullScreenToggleButton table={table} />
|
|
65
65
|
)}
|
|
66
66
|
</>
|
|
67
67
|
)}
|
|
@@ -19,10 +19,10 @@ export const commonToolbarStyles = ({ theme }: { theme: Theme }) => ({
|
|
|
19
19
|
});
|
|
20
20
|
|
|
21
21
|
interface Props {
|
|
22
|
-
|
|
22
|
+
table: MRT_TableInstance;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export const MRT_ToolbarTop: FC<Props> = ({
|
|
25
|
+
export const MRT_ToolbarTop: FC<Props> = ({ table }) => {
|
|
26
26
|
const {
|
|
27
27
|
getState,
|
|
28
28
|
options: {
|
|
@@ -36,7 +36,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
36
36
|
renderToolbarTopCustomActions,
|
|
37
37
|
tableId,
|
|
38
38
|
},
|
|
39
|
-
} =
|
|
39
|
+
} = table;
|
|
40
40
|
|
|
41
41
|
const { isFullScreen, showGlobalFilter } = getState();
|
|
42
42
|
|
|
@@ -44,7 +44,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
44
44
|
|
|
45
45
|
const toolbarProps =
|
|
46
46
|
muiTableToolbarTopProps instanceof Function
|
|
47
|
-
? muiTableToolbarTopProps({
|
|
47
|
+
? muiTableToolbarTopProps({ table })
|
|
48
48
|
: muiTableToolbarTopProps;
|
|
49
49
|
|
|
50
50
|
const stackAlertBanner =
|
|
@@ -69,7 +69,7 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
69
69
|
{positionToolbarAlertBanner === 'top' && (
|
|
70
70
|
<MRT_ToolbarAlertBanner
|
|
71
71
|
stackAlertBanner={stackAlertBanner}
|
|
72
|
-
|
|
72
|
+
table={table}
|
|
73
73
|
/>
|
|
74
74
|
)}
|
|
75
75
|
<Box
|
|
@@ -86,24 +86,24 @@ export const MRT_ToolbarTop: FC<Props> = ({ instance }) => {
|
|
|
86
86
|
}}
|
|
87
87
|
>
|
|
88
88
|
{enableGlobalFilter && positionGlobalFilter === 'left' && (
|
|
89
|
-
<MRT_GlobalFilterTextField
|
|
89
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
90
90
|
)}
|
|
91
91
|
|
|
92
|
-
{renderToolbarTopCustomActions?.({
|
|
92
|
+
{renderToolbarTopCustomActions?.({ table }) ?? <span />}
|
|
93
93
|
{enableToolbarInternalActions ? (
|
|
94
|
-
<MRT_ToolbarInternalButtons
|
|
94
|
+
<MRT_ToolbarInternalButtons table={table} />
|
|
95
95
|
) : (
|
|
96
96
|
enableGlobalFilter &&
|
|
97
97
|
positionGlobalFilter === 'right' && (
|
|
98
|
-
<MRT_GlobalFilterTextField
|
|
98
|
+
<MRT_GlobalFilterTextField table={table} />
|
|
99
99
|
)
|
|
100
100
|
)}
|
|
101
101
|
</Box>
|
|
102
102
|
{enablePagination &&
|
|
103
103
|
['top', 'both'].includes(positionPagination ?? '') && (
|
|
104
|
-
<MRT_TablePagination
|
|
104
|
+
<MRT_TablePagination table={table} position="top" />
|
|
105
105
|
)}
|
|
106
|
-
<MRT_LinearProgressBar alignTo="bottom"
|
|
106
|
+
<MRT_LinearProgressBar alignTo="bottom" table={table} />
|
|
107
107
|
</Toolbar>
|
|
108
108
|
);
|
|
109
109
|
};
|
package/src/utils.ts
CHANGED
|
@@ -1,22 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ColumnOrderState } from '@tanstack/react-table';
|
|
2
2
|
import {
|
|
3
3
|
MaterialReactTableProps,
|
|
4
4
|
MRT_Column,
|
|
5
5
|
MRT_ColumnDef,
|
|
6
|
-
|
|
6
|
+
MRT_DefinedColumnDef,
|
|
7
|
+
MRT_FilterOption,
|
|
7
8
|
} from '.';
|
|
8
9
|
import { MRT_FilterFns } from './filtersFns';
|
|
10
|
+
import { MRT_SortingFns } from './sortingFns';
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
):
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
const getColumnId = <D extends Record<string, any> = {}>(
|
|
13
|
+
columnDef: MRT_ColumnDef<D>,
|
|
14
|
+
): string =>
|
|
15
|
+
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
|
|
16
|
+
|
|
17
|
+
export const getAllLeafColumnDefs = <D extends Record<string, any> = {}>(
|
|
18
|
+
columns: MRT_ColumnDef<D>[],
|
|
19
|
+
): MRT_ColumnDef<D>[] => {
|
|
20
|
+
let lowestLevelColumns: MRT_ColumnDef<D>[] = columns;
|
|
21
|
+
let currentCols: MRT_ColumnDef<D>[] | undefined = columns;
|
|
15
22
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
16
|
-
const nextCols: MRT_ColumnDef[] = currentCols
|
|
23
|
+
const nextCols: MRT_ColumnDef<D>[] = currentCols
|
|
17
24
|
.filter((col) => !!col.columns)
|
|
18
25
|
.map((col) => col.columns)
|
|
19
|
-
.flat() as MRT_ColumnDef[];
|
|
26
|
+
.flat() as MRT_ColumnDef<D>[];
|
|
20
27
|
if (nextCols.every((col) => !col?.columns)) {
|
|
21
28
|
lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
|
|
22
29
|
}
|
|
@@ -25,42 +32,37 @@ export const getAllLeafColumnDefs = (
|
|
|
25
32
|
return lowestLevelColumns.filter((col) => !col.columns);
|
|
26
33
|
};
|
|
27
34
|
|
|
28
|
-
export const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
)
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
}) as
|
|
55
|
-
|
|
56
|
-
export const createDisplayColumn = <D extends Record<string, any> = {}>(
|
|
57
|
-
table: Table<D>,
|
|
58
|
-
column: Omit<MRT_ColumnDef<D>, 'header'> & { header?: string },
|
|
59
|
-
): ColumnDef<D> => table.createDisplayColumn(column as ColumnDef<D>);
|
|
35
|
+
export const prepareColumns = <D extends Record<string, any> = {}>(
|
|
36
|
+
columnDefs: MRT_ColumnDef<D>[],
|
|
37
|
+
currentFilterFns: { [key: string]: MRT_FilterOption },
|
|
38
|
+
): MRT_DefinedColumnDef<D>[] =>
|
|
39
|
+
columnDefs.map((columnDef) => {
|
|
40
|
+
if (!columnDef.id) columnDef.id = getColumnId(columnDef);
|
|
41
|
+
if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
|
|
42
|
+
console.error(
|
|
43
|
+
'Column definitions must have a valid `accessorKey` or `id` property',
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
|
|
47
|
+
if (!!columnDef.columns?.length) {
|
|
48
|
+
columnDef.columnDefType = 'group';
|
|
49
|
+
columnDef.columns = prepareColumns(columnDef.columns, currentFilterFns);
|
|
50
|
+
} else if (columnDef.columnDefType === 'data') {
|
|
51
|
+
if (Object.keys(MRT_FilterFns).includes(currentFilterFns[columnDef.id])) {
|
|
52
|
+
columnDef.filterFn =
|
|
53
|
+
MRT_FilterFns[currentFilterFns[columnDef.id]] ?? MRT_FilterFns.fuzzy;
|
|
54
|
+
}
|
|
55
|
+
if (Object.keys(MRT_SortingFns).includes(columnDef.sortingFn as string)) {
|
|
56
|
+
// @ts-ignore
|
|
57
|
+
columnDef.sortingFn = MRT_SortingFns[columnDef.sortingFn];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return columnDef;
|
|
61
|
+
}) as MRT_DefinedColumnDef<D>[];
|
|
60
62
|
|
|
61
|
-
export const reorderColumn = (
|
|
62
|
-
movingColumn: MRT_Column
|
|
63
|
-
receivingColumn: MRT_Column
|
|
63
|
+
export const reorderColumn = <D extends Record<string, any> = {}>(
|
|
64
|
+
movingColumn: MRT_Column<D>,
|
|
65
|
+
receivingColumn: MRT_Column<D>,
|
|
64
66
|
columnOrder: ColumnOrderState,
|
|
65
67
|
): ColumnOrderState => {
|
|
66
68
|
if (movingColumn.getCanPin()) {
|
|
@@ -74,8 +76,8 @@ export const reorderColumn = (
|
|
|
74
76
|
return [...columnOrder];
|
|
75
77
|
};
|
|
76
78
|
|
|
77
|
-
export const getLeadingDisplayColumnIds = (
|
|
78
|
-
props: MaterialReactTableProps<
|
|
79
|
+
export const getLeadingDisplayColumnIds = <D extends Record<string, any> = {}>(
|
|
80
|
+
props: MaterialReactTableProps<D>,
|
|
79
81
|
) =>
|
|
80
82
|
[
|
|
81
83
|
((props.positionActionsColumn === 'first' && props.enableRowActions) ||
|
|
@@ -86,17 +88,21 @@ export const getLeadingDisplayColumnIds = (
|
|
|
86
88
|
props.enableRowNumbers && 'mrt-row-numbers',
|
|
87
89
|
].filter(Boolean) as string[];
|
|
88
90
|
|
|
89
|
-
export const getTrailingDisplayColumnIds = (
|
|
90
|
-
props: MaterialReactTableProps<
|
|
91
|
+
export const getTrailingDisplayColumnIds = <D extends Record<string, any> = {}>(
|
|
92
|
+
props: MaterialReactTableProps<D>,
|
|
91
93
|
) => [
|
|
92
94
|
((props.positionActionsColumn === 'last' && props.enableRowActions) ||
|
|
93
95
|
(props.enableEditing && props.editingMode === 'row')) &&
|
|
94
96
|
'mrt-row-actions',
|
|
95
97
|
];
|
|
96
98
|
|
|
97
|
-
export const getDefaultColumnOrderIds =
|
|
99
|
+
export const getDefaultColumnOrderIds = <D extends Record<string, any> = {}>(
|
|
100
|
+
props: MaterialReactTableProps<D>,
|
|
101
|
+
) =>
|
|
98
102
|
[
|
|
99
103
|
...getLeadingDisplayColumnIds(props),
|
|
100
|
-
...getAllLeafColumnDefs(props.columns
|
|
104
|
+
...getAllLeafColumnDefs(props.columns).map((columnDef) =>
|
|
105
|
+
getColumnId(columnDef),
|
|
106
|
+
),
|
|
101
107
|
...getTrailingDisplayColumnIds(props),
|
|
102
108
|
].filter(Boolean) as string[];
|