material-react-table 0.22.0 → 0.23.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/README.md +90 -18
- package/dist/MaterialReactTable.d.ts +159 -153
- package/dist/filtersFns.d.ts +22 -22
- package/dist/material-react-table.cjs.development.js +11 -12
- 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 +11 -12
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/sortingFns.d.ts +2 -2
- package/dist/table/MRT_TableRoot.d.ts +1 -1
- package/dist/utils.d.ts +7 -7
- package/package.json +6 -6
- package/src/MaterialReactTable.tsx +189 -174
- package/src/buttons/MRT_CopyButton.tsx +0 -1
- package/src/buttons/MRT_ToggleFiltersButton.tsx +3 -3
- package/src/filtersFns.ts +37 -37
- package/src/head/MRT_TableHeadCellFilterContainer.tsx +2 -2
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +2 -2
- package/src/inputs/MRT_EditCellTextField.tsx +1 -1
- package/src/sortingFns.ts +6 -6
- package/src/table/MRT_TableRoot.tsx +12 -13
- package/src/utils.ts +28 -22
|
@@ -50,7 +50,6 @@ export const MRT_CopyButton: FC<Props> = ({ cell, children, table }) => {
|
|
|
50
50
|
title={copied ? localization.copiedToClipboard : localization.clickToCopy}
|
|
51
51
|
>
|
|
52
52
|
<Button
|
|
53
|
-
aria-label={localization.clickToCopy}
|
|
54
53
|
onClick={() => handleCopy(cell.getValue())}
|
|
55
54
|
size="small"
|
|
56
55
|
type="button"
|
|
@@ -15,10 +15,10 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ table, ...rest }) => {
|
|
|
15
15
|
},
|
|
16
16
|
setShowFilters,
|
|
17
17
|
} = table;
|
|
18
|
-
const {
|
|
18
|
+
const { showColumnFilters } = getState();
|
|
19
19
|
|
|
20
20
|
const handleToggleShowFilters = () => {
|
|
21
|
-
setShowFilters(!
|
|
21
|
+
setShowFilters(!showColumnFilters);
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
return (
|
|
@@ -28,7 +28,7 @@ export const MRT_ToggleFiltersButton: FC<Props> = ({ table, ...rest }) => {
|
|
|
28
28
|
onClick={handleToggleShowFilters}
|
|
29
29
|
{...rest}
|
|
30
30
|
>
|
|
31
|
-
{
|
|
31
|
+
{showColumnFilters ? <FilterListOffIcon /> : <FilterListIcon />}
|
|
32
32
|
</IconButton>
|
|
33
33
|
</Tooltip>
|
|
34
34
|
);
|
package/src/filtersFns.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { rankItem, rankings, RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
2
|
import { filterFns, Row } from '@tanstack/react-table';
|
|
3
3
|
|
|
4
|
-
export const fuzzy = <
|
|
5
|
-
row: Row<
|
|
4
|
+
export const fuzzy = <TData extends Record<string, any> = {}>(
|
|
5
|
+
row: Row<TData>,
|
|
6
6
|
columnId: string,
|
|
7
|
-
filterValue: string,
|
|
7
|
+
filterValue: string | number,
|
|
8
8
|
addMeta: (item: RankingInfo) => void,
|
|
9
9
|
) => {
|
|
10
|
-
const itemRank = rankItem(row.getValue(columnId), filterValue, {
|
|
10
|
+
const itemRank = rankItem(row.getValue(columnId), filterValue as string, {
|
|
11
11
|
threshold: rankings.MATCHES,
|
|
12
12
|
});
|
|
13
13
|
addMeta(itemRank);
|
|
@@ -16,13 +16,13 @@ export const fuzzy = <D extends Record<string, any> = {}>(
|
|
|
16
16
|
|
|
17
17
|
fuzzy.autoRemove = (val: any) => !val;
|
|
18
18
|
|
|
19
|
-
export const contains = <
|
|
20
|
-
row: Row<
|
|
19
|
+
export const contains = <TData extends Record<string, any> = {}>(
|
|
20
|
+
row: Row<TData>,
|
|
21
21
|
id: string,
|
|
22
22
|
filterValue: string | number,
|
|
23
23
|
) =>
|
|
24
24
|
row
|
|
25
|
-
.getValue(id)
|
|
25
|
+
.getValue<string | number>(id)
|
|
26
26
|
.toString()
|
|
27
27
|
.toLowerCase()
|
|
28
28
|
.trim()
|
|
@@ -30,13 +30,13 @@ export const contains = <D extends Record<string, any> = {}>(
|
|
|
30
30
|
|
|
31
31
|
contains.autoRemove = (val: any) => !val;
|
|
32
32
|
|
|
33
|
-
export const startsWith = <
|
|
34
|
-
row: Row<
|
|
33
|
+
export const startsWith = <TData extends Record<string, any> = {}>(
|
|
34
|
+
row: Row<TData>,
|
|
35
35
|
id: string,
|
|
36
36
|
filterValue: string | number,
|
|
37
37
|
) =>
|
|
38
38
|
row
|
|
39
|
-
.getValue(id)
|
|
39
|
+
.getValue<string | number>(id)
|
|
40
40
|
.toString()
|
|
41
41
|
.toLowerCase()
|
|
42
42
|
.trim()
|
|
@@ -44,13 +44,13 @@ export const startsWith = <D extends Record<string, any> = {}>(
|
|
|
44
44
|
|
|
45
45
|
startsWith.autoRemove = (val: any) => !val;
|
|
46
46
|
|
|
47
|
-
export const endsWith = <
|
|
48
|
-
row: Row<
|
|
47
|
+
export const endsWith = <TData extends Record<string, any> = {}>(
|
|
48
|
+
row: Row<TData>,
|
|
49
49
|
id: string,
|
|
50
50
|
filterValue: string | number,
|
|
51
51
|
) =>
|
|
52
52
|
row
|
|
53
|
-
.getValue(id)
|
|
53
|
+
.getValue<string | number>(id)
|
|
54
54
|
.toString()
|
|
55
55
|
.toLowerCase()
|
|
56
56
|
.trim()
|
|
@@ -58,52 +58,52 @@ export const endsWith = <D extends Record<string, any> = {}>(
|
|
|
58
58
|
|
|
59
59
|
endsWith.autoRemove = (val: any) => !val;
|
|
60
60
|
|
|
61
|
-
export const equals = <
|
|
62
|
-
row: Row<
|
|
61
|
+
export const equals = <TData extends Record<string, any> = {}>(
|
|
62
|
+
row: Row<TData>,
|
|
63
63
|
id: string,
|
|
64
64
|
filterValue: string | number,
|
|
65
65
|
) =>
|
|
66
|
-
row.getValue(id).toString().toLowerCase().trim() ===
|
|
66
|
+
row.getValue<string | number>(id).toString().toLowerCase().trim() ===
|
|
67
67
|
filterValue.toString().toLowerCase().trim();
|
|
68
68
|
|
|
69
69
|
equals.autoRemove = (val: any) => !val;
|
|
70
70
|
|
|
71
|
-
export const notEquals = <
|
|
72
|
-
row: Row<
|
|
71
|
+
export const notEquals = <TData extends Record<string, any> = {}>(
|
|
72
|
+
row: Row<TData>,
|
|
73
73
|
id: string,
|
|
74
74
|
filterValue: string | number,
|
|
75
75
|
) =>
|
|
76
|
-
row.getValue(id).toString().toLowerCase().trim() !==
|
|
76
|
+
row.getValue<string | number>(id).toString().toLowerCase().trim() !==
|
|
77
77
|
filterValue.toString().toLowerCase().trim();
|
|
78
78
|
|
|
79
79
|
notEquals.autoRemove = (val: any) => !val;
|
|
80
80
|
|
|
81
|
-
export const greaterThan = <
|
|
82
|
-
row: Row<
|
|
81
|
+
export const greaterThan = <TData extends Record<string, any> = {}>(
|
|
82
|
+
row: Row<TData>,
|
|
83
83
|
id: string,
|
|
84
84
|
filterValue: string | number,
|
|
85
85
|
) =>
|
|
86
|
-
!isNaN(+filterValue) && !isNaN(+row.getValue(id))
|
|
87
|
-
? +row.getValue(id) >= +filterValue
|
|
88
|
-
: row.getValue(id).toString().toLowerCase().trim() >
|
|
86
|
+
!isNaN(+filterValue) && !isNaN(+row.getValue<string | number>(id))
|
|
87
|
+
? +row.getValue<string | number>(id) >= +filterValue
|
|
88
|
+
: row.getValue<string | number>(id).toString().toLowerCase().trim() >
|
|
89
89
|
filterValue.toString().toLowerCase().trim();
|
|
90
90
|
|
|
91
91
|
greaterThan.autoRemove = (val: any) => !val;
|
|
92
92
|
|
|
93
|
-
export const lessThan = <
|
|
94
|
-
row: Row<
|
|
93
|
+
export const lessThan = <TData extends Record<string, any> = {}>(
|
|
94
|
+
row: Row<TData>,
|
|
95
95
|
id: string,
|
|
96
96
|
filterValue: string | number,
|
|
97
97
|
) =>
|
|
98
|
-
!isNaN(+filterValue) && !isNaN(+row.getValue(id))
|
|
99
|
-
? +row.getValue(id) <= +filterValue
|
|
100
|
-
: row.getValue(id).toString().toLowerCase().trim() <
|
|
98
|
+
!isNaN(+filterValue) && !isNaN(+row.getValue<string | number>(id))
|
|
99
|
+
? +row.getValue<string | number>(id) <= +filterValue
|
|
100
|
+
: row.getValue<string | number>(id).toString().toLowerCase().trim() <
|
|
101
101
|
filterValue.toString().toLowerCase().trim();
|
|
102
102
|
|
|
103
103
|
lessThan.autoRemove = (val: any) => !val;
|
|
104
104
|
|
|
105
|
-
export const between = <
|
|
106
|
-
row: Row<
|
|
105
|
+
export const between = <TData extends Record<string, any> = {}>(
|
|
106
|
+
row: Row<TData>,
|
|
107
107
|
id: string,
|
|
108
108
|
filterValues: [string | number, string | number],
|
|
109
109
|
) =>
|
|
@@ -117,19 +117,19 @@ export const between = <D extends Record<string, any> = {}>(
|
|
|
117
117
|
|
|
118
118
|
between.autoRemove = (val: any) => !val;
|
|
119
119
|
|
|
120
|
-
export const empty = <
|
|
121
|
-
row: Row<
|
|
120
|
+
export const empty = <TData extends Record<string, any> = {}>(
|
|
121
|
+
row: Row<TData>,
|
|
122
122
|
id: string,
|
|
123
123
|
_filterValue: string | number,
|
|
124
|
-
) => !row.getValue(id).toString().trim();
|
|
124
|
+
) => !row.getValue<string | number>(id).toString().trim();
|
|
125
125
|
|
|
126
126
|
empty.autoRemove = (val: any) => !val;
|
|
127
127
|
|
|
128
|
-
export const notEmpty = <
|
|
129
|
-
row: Row<
|
|
128
|
+
export const notEmpty = <TData extends Record<string, any> = {}>(
|
|
129
|
+
row: Row<TData>,
|
|
130
130
|
id: string,
|
|
131
131
|
_filterValue: string | number,
|
|
132
|
-
) => !!row.getValue(id).toString().trim();
|
|
132
|
+
) => !!row.getValue<string | number>(id).toString().trim();
|
|
133
133
|
|
|
134
134
|
notEmpty.autoRemove = (val: any) => !val;
|
|
135
135
|
|
|
@@ -14,11 +14,11 @@ export const MRT_TableHeadCellFilterContainer: FC<Props> = ({
|
|
|
14
14
|
table,
|
|
15
15
|
}) => {
|
|
16
16
|
const { getState } = table;
|
|
17
|
-
const { currentFilterFns,
|
|
17
|
+
const { currentFilterFns, showColumnFilters } = getState();
|
|
18
18
|
const { column } = header;
|
|
19
19
|
|
|
20
20
|
return (
|
|
21
|
-
<Collapse in={
|
|
21
|
+
<Collapse in={showColumnFilters} mountOnEnter unmountOnExit>
|
|
22
22
|
{currentFilterFns[column.id] === 'between' ? (
|
|
23
23
|
<MRT_FilterRangeFields header={header} table={table} />
|
|
24
24
|
) : (
|
|
@@ -12,7 +12,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
12
12
|
getState,
|
|
13
13
|
options: { columnResizeMode },
|
|
14
14
|
} = table;
|
|
15
|
-
const { density,
|
|
15
|
+
const { density, showColumnFilters } = getState();
|
|
16
16
|
const { column } = header;
|
|
17
17
|
const { columnDef } = column;
|
|
18
18
|
const { columnDefType } = columnDef;
|
|
@@ -26,7 +26,7 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
26
26
|
borderRadius: '2px',
|
|
27
27
|
borderRightWidth: '2px',
|
|
28
28
|
cursor: 'col-resize',
|
|
29
|
-
height:
|
|
29
|
+
height: showColumnFilters && columnDefType === 'data' ? '4rem' : '2rem',
|
|
30
30
|
mr: density === 'compact' ? '-0.5rem' : '-1rem',
|
|
31
31
|
opacity: 0.8,
|
|
32
32
|
position: 'absolute',
|
|
@@ -29,7 +29,7 @@ export const MRT_EditCellTextField: FC<Props> = ({ cell, table }) => {
|
|
|
29
29
|
const { column, row } = cell;
|
|
30
30
|
const { columnDef } = column;
|
|
31
31
|
|
|
32
|
-
const [value, setValue] = useState(cell.getValue());
|
|
32
|
+
const [value, setValue] = useState(cell.getValue<string>());
|
|
33
33
|
|
|
34
34
|
const handleChange = (event: ChangeEvent<HTMLInputElement>) => {
|
|
35
35
|
setValue(event.target.value);
|
package/src/sortingFns.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { compareItems, RankingInfo } from '@tanstack/match-sorter-utils';
|
|
|
2
2
|
import { Row, sortingFns } from '@tanstack/react-table';
|
|
3
3
|
import { MRT_Row } from '.';
|
|
4
4
|
|
|
5
|
-
const fuzzy = <
|
|
6
|
-
rowA: Row<
|
|
7
|
-
rowB: Row<
|
|
5
|
+
const fuzzy = <TData extends Record<string, any> = {}>(
|
|
6
|
+
rowA: Row<TData>,
|
|
7
|
+
rowB: Row<TData>,
|
|
8
8
|
columnId: string,
|
|
9
9
|
) => {
|
|
10
10
|
let dir = 0;
|
|
@@ -25,9 +25,9 @@ export const MRT_SortingFns = {
|
|
|
25
25
|
fuzzy,
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
export const rankGlobalFuzzy = <
|
|
29
|
-
rowA: MRT_Row<
|
|
30
|
-
rowB: MRT_Row<
|
|
28
|
+
export const rankGlobalFuzzy = <TData extends Record<string, any> = {}>(
|
|
29
|
+
rowA: MRT_Row<TData>,
|
|
30
|
+
rowB: MRT_Row<TData>,
|
|
31
31
|
) =>
|
|
32
32
|
Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
|
|
33
33
|
Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
|
|
@@ -32,8 +32,8 @@ import {
|
|
|
32
32
|
} from '../utils';
|
|
33
33
|
import { MRT_FilterFns } from '../filtersFns';
|
|
34
34
|
|
|
35
|
-
export const MRT_TableRoot = <
|
|
36
|
-
props: MaterialReactTableProps<
|
|
35
|
+
export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
36
|
+
props: MaterialReactTableProps<TData>,
|
|
37
37
|
) => {
|
|
38
38
|
const [tableId, setIdPrefix] = useState(props.tableId);
|
|
39
39
|
useEffect(
|
|
@@ -42,7 +42,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
42
42
|
[props.tableId],
|
|
43
43
|
);
|
|
44
44
|
|
|
45
|
-
const initialState: Partial<MRT_TableState<
|
|
45
|
+
const initialState: Partial<MRT_TableState<TData>> = useMemo(() => {
|
|
46
46
|
const initState = props.initialState ?? {};
|
|
47
47
|
initState.columnOrder =
|
|
48
48
|
initState.columnOrder ?? getDefaultColumnOrderIds(props);
|
|
@@ -53,10 +53,9 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
53
53
|
initialState.columnOrder ?? [],
|
|
54
54
|
);
|
|
55
55
|
const [currentEditingCell, setCurrentEditingCell] =
|
|
56
|
-
useState<MRT_Cell<
|
|
57
|
-
const [currentEditingRow, setCurrentEditingRow] =
|
|
58
|
-
initialState?.currentEditingRow ?? null
|
|
59
|
-
);
|
|
56
|
+
useState<MRT_Cell<TData> | null>(initialState?.currentEditingCell ?? null);
|
|
57
|
+
const [currentEditingRow, setCurrentEditingRow] =
|
|
58
|
+
useState<MRT_Row<TData> | null>(initialState?.currentEditingRow ?? null);
|
|
60
59
|
const [density, setDensity] = useState(
|
|
61
60
|
initialState?.density ?? 'comfortable',
|
|
62
61
|
);
|
|
@@ -66,8 +65,8 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
66
65
|
const [showAlertBanner, setShowAlertBanner] = useState(
|
|
67
66
|
props.initialState?.showAlertBanner ?? false,
|
|
68
67
|
);
|
|
69
|
-
const [
|
|
70
|
-
initialState?.
|
|
68
|
+
const [showColumnFilters, setShowFilters] = useState(
|
|
69
|
+
initialState?.showColumnFilters ?? false,
|
|
71
70
|
);
|
|
72
71
|
const [showGlobalFilter, setShowGlobalFilter] = useState(
|
|
73
72
|
initialState?.showGlobalFilter ?? false,
|
|
@@ -78,7 +77,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
78
77
|
}>(() =>
|
|
79
78
|
Object.assign(
|
|
80
79
|
{},
|
|
81
|
-
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<
|
|
80
|
+
...getAllLeafColumnDefs(props.columns as MRT_ColumnDef<TData>[]).map(
|
|
82
81
|
(col) => ({
|
|
83
82
|
[col.id?.toString() ?? col.accessorKey?.toString() ?? '']:
|
|
84
83
|
col.filterFn instanceof Function
|
|
@@ -158,7 +157,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
158
157
|
muiTableHeadCellProps: props.muiTableHeadCellProps,
|
|
159
158
|
size: 60,
|
|
160
159
|
},
|
|
161
|
-
] as MRT_ColumnDef<
|
|
160
|
+
] as MRT_ColumnDef<TData>[]
|
|
162
161
|
).filter(Boolean),
|
|
163
162
|
[
|
|
164
163
|
columnOrder,
|
|
@@ -184,7 +183,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
184
183
|
[currentFilterFns, displayColumns, props.columns],
|
|
185
184
|
);
|
|
186
185
|
|
|
187
|
-
const data:
|
|
186
|
+
const data: TData[] = useMemo(
|
|
188
187
|
() =>
|
|
189
188
|
(props.state?.isLoading || props.state?.showSkeletons) &&
|
|
190
189
|
!props.data.length
|
|
@@ -231,7 +230,7 @@ export const MRT_TableRoot = <D extends Record<string, any> = {}>(
|
|
|
231
230
|
density,
|
|
232
231
|
isFullScreen,
|
|
233
232
|
showAlertBanner,
|
|
234
|
-
|
|
233
|
+
showColumnFilters,
|
|
235
234
|
showGlobalFilter,
|
|
236
235
|
...props.state,
|
|
237
236
|
} as TableState,
|
package/src/utils.ts
CHANGED
|
@@ -9,21 +9,21 @@ import {
|
|
|
9
9
|
import { MRT_FilterFns } from './filtersFns';
|
|
10
10
|
import { MRT_SortingFns } from './sortingFns';
|
|
11
11
|
|
|
12
|
-
const getColumnId = <
|
|
13
|
-
columnDef: MRT_ColumnDef<
|
|
12
|
+
const getColumnId = <TData extends Record<string, any> = {}>(
|
|
13
|
+
columnDef: MRT_ColumnDef<TData>,
|
|
14
14
|
): string =>
|
|
15
15
|
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
|
|
16
16
|
|
|
17
|
-
export const getAllLeafColumnDefs = <
|
|
18
|
-
columns: MRT_ColumnDef<
|
|
19
|
-
): MRT_ColumnDef<
|
|
20
|
-
let lowestLevelColumns: MRT_ColumnDef<
|
|
21
|
-
let currentCols: MRT_ColumnDef<
|
|
17
|
+
export const getAllLeafColumnDefs = <TData extends Record<string, any> = {}>(
|
|
18
|
+
columns: MRT_ColumnDef<TData>[],
|
|
19
|
+
): MRT_ColumnDef<TData>[] => {
|
|
20
|
+
let lowestLevelColumns: MRT_ColumnDef<TData>[] = columns;
|
|
21
|
+
let currentCols: MRT_ColumnDef<TData>[] | undefined = columns;
|
|
22
22
|
while (!!currentCols?.length && currentCols.some((col) => col.columns)) {
|
|
23
|
-
const nextCols: MRT_ColumnDef<
|
|
23
|
+
const nextCols: MRT_ColumnDef<TData>[] = currentCols
|
|
24
24
|
.filter((col) => !!col.columns)
|
|
25
25
|
.map((col) => col.columns)
|
|
26
|
-
.flat() as MRT_ColumnDef<
|
|
26
|
+
.flat() as MRT_ColumnDef<TData>[];
|
|
27
27
|
if (nextCols.every((col) => !col?.columns)) {
|
|
28
28
|
lowestLevelColumns = [...lowestLevelColumns, ...nextCols];
|
|
29
29
|
}
|
|
@@ -32,10 +32,10 @@ export const getAllLeafColumnDefs = <D extends Record<string, any> = {}>(
|
|
|
32
32
|
return lowestLevelColumns.filter((col) => !col.columns);
|
|
33
33
|
};
|
|
34
34
|
|
|
35
|
-
export const prepareColumns = <
|
|
36
|
-
columnDefs: MRT_ColumnDef<
|
|
35
|
+
export const prepareColumns = <TData extends Record<string, any> = {}>(
|
|
36
|
+
columnDefs: MRT_ColumnDef<TData>[],
|
|
37
37
|
currentFilterFns: { [key: string]: MRT_FilterOption },
|
|
38
|
-
): MRT_DefinedColumnDef<
|
|
38
|
+
): MRT_DefinedColumnDef<TData>[] =>
|
|
39
39
|
columnDefs.map((columnDef) => {
|
|
40
40
|
if (!columnDef.id) columnDef.id = getColumnId(columnDef);
|
|
41
41
|
if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
|
|
@@ -58,11 +58,11 @@ export const prepareColumns = <D extends Record<string, any> = {}>(
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
return columnDef;
|
|
61
|
-
}) as MRT_DefinedColumnDef<
|
|
61
|
+
}) as MRT_DefinedColumnDef<TData>[];
|
|
62
62
|
|
|
63
|
-
export const reorderColumn = <
|
|
64
|
-
movingColumn: MRT_Column<
|
|
65
|
-
receivingColumn: MRT_Column<
|
|
63
|
+
export const reorderColumn = <TData extends Record<string, any> = {}>(
|
|
64
|
+
movingColumn: MRT_Column<TData>,
|
|
65
|
+
receivingColumn: MRT_Column<TData>,
|
|
66
66
|
columnOrder: ColumnOrderState,
|
|
67
67
|
): ColumnOrderState => {
|
|
68
68
|
if (movingColumn.getCanPin()) {
|
|
@@ -76,8 +76,10 @@ export const reorderColumn = <D extends Record<string, any> = {}>(
|
|
|
76
76
|
return [...columnOrder];
|
|
77
77
|
};
|
|
78
78
|
|
|
79
|
-
export const getLeadingDisplayColumnIds = <
|
|
80
|
-
|
|
79
|
+
export const getLeadingDisplayColumnIds = <
|
|
80
|
+
TData extends Record<string, any> = {},
|
|
81
|
+
>(
|
|
82
|
+
props: MaterialReactTableProps<TData>,
|
|
81
83
|
) =>
|
|
82
84
|
[
|
|
83
85
|
((props.positionActionsColumn === 'first' && props.enableRowActions) ||
|
|
@@ -88,16 +90,20 @@ export const getLeadingDisplayColumnIds = <D extends Record<string, any> = {}>(
|
|
|
88
90
|
props.enableRowNumbers && 'mrt-row-numbers',
|
|
89
91
|
].filter(Boolean) as string[];
|
|
90
92
|
|
|
91
|
-
export const getTrailingDisplayColumnIds = <
|
|
92
|
-
|
|
93
|
+
export const getTrailingDisplayColumnIds = <
|
|
94
|
+
TData extends Record<string, any> = {},
|
|
95
|
+
>(
|
|
96
|
+
props: MaterialReactTableProps<TData>,
|
|
93
97
|
) => [
|
|
94
98
|
((props.positionActionsColumn === 'last' && props.enableRowActions) ||
|
|
95
99
|
(props.enableEditing && props.editingMode === 'row')) &&
|
|
96
100
|
'mrt-row-actions',
|
|
97
101
|
];
|
|
98
102
|
|
|
99
|
-
export const getDefaultColumnOrderIds = <
|
|
100
|
-
|
|
103
|
+
export const getDefaultColumnOrderIds = <
|
|
104
|
+
TData extends Record<string, any> = {},
|
|
105
|
+
>(
|
|
106
|
+
props: MaterialReactTableProps<TData>,
|
|
101
107
|
) =>
|
|
102
108
|
[
|
|
103
109
|
...getLeadingDisplayColumnIds(props),
|