@cutting/material-react-table 5.0.0-beta.2 → 5.1.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 +1 -4
- package/dist/index.d.ts +189 -524
- package/dist/index.js +329 -345
- package/dist/index.js.map +1 -1
- package/locales/ar/index.mjs +1 -2
- package/locales/az/index.mjs +1 -2
- package/locales/bg/index.mjs +1 -2
- package/locales/cs/index.mjs +1 -2
- package/locales/da/index.mjs +1 -2
- package/locales/de/index.mjs +1 -2
- package/locales/el/index.mjs +1 -2
- package/locales/en/index.mjs +1 -2
- package/locales/es/index.mjs +1 -2
- package/locales/et/index.mjs +1 -2
- package/locales/fa/index.mjs +1 -2
- package/locales/fi/index.mjs +1 -2
- package/locales/fr/index.mjs +1 -2
- package/locales/he/index.mjs +1 -2
- package/locales/hr/index.mjs +1 -2
- package/locales/hu/index.mjs +1 -2
- package/locales/hy/index.mjs +1 -2
- package/locales/id/index.mjs +1 -2
- package/locales/it/index.mjs +1 -2
- package/locales/ja/index.mjs +1 -2
- package/locales/ko/index.mjs +1 -2
- package/locales/nl/index.mjs +1 -2
- package/locales/no/index.mjs +1 -2
- package/locales/np/index.mjs +1 -2
- package/locales/pl/index.mjs +1 -2
- package/locales/pt/index.mjs +1 -2
- package/locales/pt-BR/index.mjs +1 -2
- package/locales/ro/index.mjs +1 -2
- package/locales/ru/index.mjs +1 -2
- package/locales/sk/index.mjs +1 -2
- package/locales/sr-Cyrl-RS/index.mjs +1 -2
- package/locales/sr-Latn-RS/index.mjs +1 -2
- package/locales/sv/index.mjs +1 -2
- package/locales/tr/index.mjs +1 -2
- package/locales/uk/index.mjs +1 -2
- package/locales/vi/index.mjs +1 -2
- package/locales/zh-Hans/index.mjs +1 -2
- package/locales/zh-Hant/index.mjs +1 -2
- package/package.json +32 -40
- package/src/MaterialReactTable.smoke.test.tsx +3 -9
- package/src/components/MaterialReactTable.tsx +13 -21
- package/src/components/body/MRT_TableBody.tsx +67 -82
- package/src/components/body/MRT_TableBodyCell.tsx +38 -80
- package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
- package/src/components/body/MRT_TableBodyRow.tsx +55 -102
- package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
- package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
- package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
- package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
- package/src/components/buttons/MRT_CopyButton.tsx +7 -15
- package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
- package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
- package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
- package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
- package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
- package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
- package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
- package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
- package/src/components/footer/MRT_TableFooter.tsx +9 -16
- package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
- package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
- package/src/components/head/MRT_TableHead.tsx +8 -18
- package/src/components/head/MRT_TableHeadCell.tsx +46 -100
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
- package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
- package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
- package/src/components/head/MRT_TableHeadRow.tsx +24 -36
- package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
- package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
- package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
- package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
- package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
- package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
- package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
- package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
- package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
- package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
- package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
- package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
- package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
- package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
- package/src/components/modals/MRT_EditRowModal.tsx +8 -26
- package/src/components/table/MRT_Table.tsx +12 -20
- package/src/components/table/MRT_TableContainer.test.tsx +147 -0
- package/src/components/table/MRT_TableContainer.tsx +33 -37
- package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
- package/src/components/table/MRT_TablePaper.tsx +7 -14
- package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
- package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
- package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
- package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
- package/src/fns/aggregationFns.test.tsx +1 -3
- package/src/fns/filterFns.test.tsx +9 -37
- package/src/fns/filterFns.ts +73 -96
- package/src/fns/sortingFns.test.tsx +39 -0
- package/src/fns/sortingFns.ts +15 -15
- package/src/fns/tableFeatures.test.tsx +6 -29
- package/src/fns/tableFeatures.ts +5 -4
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
- package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
- package/src/hooks/useMRT_Effects.test.tsx +114 -0
- package/src/hooks/useMRT_Effects.ts +26 -27
- package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
- package/src/hooks/useMRT_Rows.ts +3 -42
- package/src/hooks/useMRT_TableInstance.ts +63 -129
- package/src/hooks/useMRT_TableOptions.ts +15 -29
- package/src/hooks/useMaterialReactTable.ts +2 -7
- package/src/icons.ts +38 -1
- package/src/index.ts +0 -4
- package/src/locales/ar.ts +1 -2
- package/src/locales/az.ts +1 -2
- package/src/locales/bg.ts +1 -2
- package/src/locales/cs.ts +2 -4
- package/src/locales/da.ts +1 -2
- package/src/locales/de.ts +1 -2
- package/src/locales/el.ts +1 -2
- package/src/locales/en.ts +1 -2
- package/src/locales/es.ts +1 -2
- package/src/locales/et.ts +2 -4
- package/src/locales/fa.ts +1 -2
- package/src/locales/fi.ts +2 -4
- package/src/locales/fr.ts +1 -2
- package/src/locales/he.ts +1 -2
- package/src/locales/hr.ts +1 -2
- package/src/locales/hu.ts +1 -2
- package/src/locales/hy.ts +1 -2
- package/src/locales/id.ts +2 -4
- package/src/locales/it.ts +1 -2
- package/src/locales/ja.ts +1 -2
- package/src/locales/ko.ts +1 -2
- package/src/locales/nl.ts +1 -2
- package/src/locales/no.ts +2 -4
- package/src/locales/np.ts +2 -4
- package/src/locales/pl.ts +1 -2
- package/src/locales/pt-BR.ts +1 -2
- package/src/locales/pt.ts +1 -2
- package/src/locales/ro.ts +1 -2
- package/src/locales/ru.ts +1 -2
- package/src/locales/sk.ts +2 -4
- package/src/locales/sr-Cyrl-RS.ts +1 -2
- package/src/locales/sr-Latn-RS.ts +1 -2
- package/src/locales/sv.ts +1 -2
- package/src/locales/tr.ts +1 -2
- package/src/locales/uk.ts +1 -2
- package/src/locales/vi.ts +1 -2
- package/src/types.ts +156 -349
- package/src/utils/cell.utils.ts +30 -68
- package/src/utils/column.utils.ts +61 -49
- package/src/utils/displayColumn.utils.ts +16 -38
- package/src/utils/highlight.utils.ts +7 -11
- package/src/utils/row.utils.ts +40 -65
- package/src/utils/slotProps.utils.ts +1 -4
- package/src/utils/style.utils.ts +18 -46
- package/src/utils/tanstack.helpers.ts +10 -17
- package/src/utils/utils.ts +6 -10
- package/src/utils/virtualization.utils.ts +5 -9
|
@@ -1,39 +1,29 @@
|
|
|
1
1
|
import { useEffect, useReducer, useRef } from 'react';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
type MRT_RowData,
|
|
5
|
-
type MRT_SortingState,
|
|
6
|
-
type MRT_TableInstance,
|
|
7
|
-
} from '../types';
|
|
3
|
+
import { type MRT_RowData, type MRT_SortingState, type MRT_TableInstance } from '../types';
|
|
8
4
|
import { getDefaultColumnOrderIds } from '../utils/displayColumn.utils';
|
|
9
5
|
import { getCanRankRows } from '../utils/row.utils';
|
|
10
6
|
|
|
11
|
-
export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
12
|
-
table: MRT_TableInstance<TData>,
|
|
13
|
-
) => {
|
|
7
|
+
export const useMRT_Effects = <TData extends MRT_RowData>(table: MRT_TableInstance<TData>): void => {
|
|
14
8
|
const {
|
|
15
|
-
getIsSomeRowsPinned,
|
|
16
9
|
getPrePaginatedRowModel,
|
|
17
10
|
options: { enablePagination, enableRowPinning, rowCount },
|
|
18
11
|
} = table;
|
|
19
|
-
const {
|
|
20
|
-
|
|
21
|
-
density,
|
|
22
|
-
globalFilter,
|
|
23
|
-
isFullScreen,
|
|
24
|
-
isLoading,
|
|
25
|
-
pagination,
|
|
26
|
-
showSkeletons,
|
|
27
|
-
sorting,
|
|
28
|
-
} = table.state;
|
|
12
|
+
const { columnOrder, density, globalFilter, isFullScreen, isLoading, pagination, showSkeletons, sorting } =
|
|
13
|
+
table.state;
|
|
29
14
|
|
|
30
15
|
const totalColumnCount = table.options.columns.length;
|
|
31
16
|
const totalRowCount = rowCount ?? getPrePaginatedRowModel().rows.length;
|
|
32
17
|
|
|
33
|
-
const rerender = useReducer(() => ({}), {})
|
|
18
|
+
const [, rerender] = useReducer(() => ({}), {});
|
|
34
19
|
const initialBodyHeight = useRef<string>(null);
|
|
35
20
|
const previousTop = useRef<number>(null);
|
|
36
21
|
|
|
22
|
+
const effectValues = useRef({ columnOrder, enableRowPinning, pagination, table, tableOptions: table.options });
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
effectValues.current = { columnOrder, enableRowPinning, pagination, table, tableOptions: table.options };
|
|
25
|
+
});
|
|
26
|
+
|
|
37
27
|
useEffect(() => {
|
|
38
28
|
if (typeof window !== 'undefined') {
|
|
39
29
|
initialBodyHeight.current = document.body.style.height;
|
|
@@ -48,7 +38,9 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
48
38
|
document.body.style.height = '100dvh'; //hide page scrollbars when table is in full screen mode
|
|
49
39
|
} else {
|
|
50
40
|
document.body.style.height = initialBodyHeight.current as string;
|
|
51
|
-
if (!previousTop.current)
|
|
41
|
+
if (!previousTop.current) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
52
44
|
//restore scroll position
|
|
53
45
|
window.scrollTo({
|
|
54
46
|
behavior: 'instant',
|
|
@@ -60,17 +52,20 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
60
52
|
|
|
61
53
|
//recalculate column order when columns change or features are toggled on/off
|
|
62
54
|
useEffect(() => {
|
|
55
|
+
const { columnOrder, table, tableOptions } = effectValues.current;
|
|
63
56
|
if (totalColumnCount !== columnOrder.length) {
|
|
64
|
-
table.setColumnOrder(getDefaultColumnOrderIds(
|
|
57
|
+
table.setColumnOrder(getDefaultColumnOrderIds(tableOptions));
|
|
65
58
|
}
|
|
66
59
|
}, [totalColumnCount]);
|
|
67
60
|
|
|
68
61
|
//if page index is out of bounds, set it to the last page
|
|
69
62
|
useEffect(() => {
|
|
70
|
-
if (!enablePagination || isLoading || showSkeletons)
|
|
63
|
+
if (!enablePagination || isLoading || showSkeletons) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const { pagination, table } = effectValues.current;
|
|
71
67
|
const { pageIndex, pageSize } = pagination;
|
|
72
|
-
const totalPages: number =
|
|
73
|
-
totalRowCount > 0 ? Math.ceil(totalRowCount / pageSize) : 1;
|
|
68
|
+
const totalPages: number = totalRowCount > 0 ? Math.ceil(totalRowCount / pageSize) : 1;
|
|
74
69
|
const isOutOfBounds: boolean = pageIndex < 0 || pageIndex >= totalPages;
|
|
75
70
|
|
|
76
71
|
if (isOutOfBounds) {
|
|
@@ -87,7 +82,10 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
87
82
|
}, [sorting]);
|
|
88
83
|
|
|
89
84
|
useEffect(() => {
|
|
90
|
-
|
|
85
|
+
const { table } = effectValues.current;
|
|
86
|
+
if (!getCanRankRows(table)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
91
89
|
if (globalFilter) {
|
|
92
90
|
table.setSorting([]);
|
|
93
91
|
} else {
|
|
@@ -97,7 +95,8 @@ export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
|
97
95
|
|
|
98
96
|
//fix pinned row top style when density changes
|
|
99
97
|
useEffect(() => {
|
|
100
|
-
|
|
98
|
+
const { enableRowPinning, table } = effectValues.current;
|
|
99
|
+
if (enableRowPinning && table.getIsSomeRowsPinned()) {
|
|
101
100
|
setTimeout(() => {
|
|
102
101
|
rerender();
|
|
103
102
|
}, 150);
|
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
import { type Range, useVirtualizer } from '@tanstack/react-virtual';
|
|
2
2
|
import { useCallback, useMemo } from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
type MRT_Row,
|
|
6
|
-
type MRT_RowData,
|
|
7
|
-
type MRT_RowVirtualizer,
|
|
8
|
-
type MRT_TableInstance,
|
|
9
|
-
} from '../types';
|
|
4
|
+
import { type MRT_Row, type MRT_RowData, type MRT_RowVirtualizer, type MRT_TableInstance } from '../types';
|
|
10
5
|
import { parseFromValuesOrFunc } from '../utils/utils';
|
|
11
6
|
import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
|
|
12
7
|
|
|
@@ -20,51 +15,37 @@ export const useMRT_RowVirtualizer = <
|
|
|
20
15
|
): MRT_RowVirtualizer<TScrollElement, TItemElement> | undefined => {
|
|
21
16
|
const {
|
|
22
17
|
getRowModel,
|
|
23
|
-
options: {
|
|
24
|
-
enableRowVirtualization,
|
|
25
|
-
renderDetailPanel,
|
|
26
|
-
rowVirtualizerInstanceRef,
|
|
27
|
-
rowVirtualizerOptions,
|
|
28
|
-
},
|
|
18
|
+
options: { enableRowVirtualization, renderDetailPanel, rowVirtualizerInstanceRef, rowVirtualizerOptions },
|
|
29
19
|
refs: { tableContainerRef },
|
|
30
20
|
} = table;
|
|
31
21
|
const { density, draggingRow, expanded } = table.state;
|
|
32
22
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
23
|
+
const rowVirtualizerProps = enableRowVirtualization
|
|
24
|
+
? parseFromValuesOrFunc(rowVirtualizerOptions, {
|
|
25
|
+
table,
|
|
26
|
+
})
|
|
27
|
+
: undefined;
|
|
38
28
|
|
|
39
29
|
const realRows = rows ?? getRowModel().rows;
|
|
40
30
|
/**
|
|
41
31
|
* when filtering, should find the correct index in filtered rows
|
|
42
32
|
*/
|
|
43
33
|
const draggingRowIndex = useMemo(
|
|
44
|
-
() =>
|
|
45
|
-
draggingRow?.id
|
|
46
|
-
? realRows.findIndex((r) => r.id === draggingRow?.id)
|
|
47
|
-
: undefined,
|
|
34
|
+
() => (draggingRow?.id ? realRows.findIndex((r) => r.id === draggingRow?.id) : undefined),
|
|
48
35
|
[realRows, draggingRow?.id],
|
|
49
36
|
);
|
|
50
37
|
|
|
51
38
|
const rowCount = realRows.length;
|
|
52
39
|
|
|
53
|
-
const normalRowHeight =
|
|
54
|
-
density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73;
|
|
40
|
+
const normalRowHeight = density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73;
|
|
55
41
|
|
|
56
42
|
const rowVirtualizer = useVirtualizer({
|
|
57
43
|
count: renderDetailPanel ? rowCount * 2 : rowCount,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
? expanded === true
|
|
61
|
-
? 100
|
|
62
|
-
: 0
|
|
63
|
-
: normalRowHeight,
|
|
44
|
+
enabled: !!enableRowVirtualization,
|
|
45
|
+
estimateSize: (index) => (renderDetailPanel && index % 2 === 1 ? (expanded === true ? 100 : 0) : normalRowHeight),
|
|
64
46
|
getScrollElement: () => tableContainerRef.current,
|
|
65
47
|
measureElement:
|
|
66
|
-
typeof window !== 'undefined' &&
|
|
67
|
-
navigator.userAgent.indexOf('Firefox') === -1
|
|
48
|
+
typeof window !== 'undefined' && navigator.userAgent.indexOf('Firefox') === -1
|
|
68
49
|
? (element) => element?.getBoundingClientRect().height
|
|
69
50
|
: undefined,
|
|
70
51
|
overscan: 4,
|
|
@@ -77,10 +58,14 @@ export const useMRT_RowVirtualizer = <
|
|
|
77
58
|
...rowVirtualizerProps,
|
|
78
59
|
}) as unknown as MRT_RowVirtualizer<TScrollElement, TItemElement>;
|
|
79
60
|
|
|
80
|
-
|
|
61
|
+
if (!enableRowVirtualization) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
rowVirtualizer.virtualRows = rowVirtualizer.getVirtualItems();
|
|
81
66
|
|
|
82
67
|
if (rowVirtualizerInstanceRef) {
|
|
83
|
-
|
|
68
|
+
// @ts-expect-error: the ref is typed for the default element generics, this virtualizer uses TScrollElement and TItemElement
|
|
84
69
|
rowVirtualizerInstanceRef.current = rowVirtualizer;
|
|
85
70
|
}
|
|
86
71
|
|
package/src/hooks/useMRT_Rows.ts
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
type MRT_Row,
|
|
5
|
-
type MRT_RowData,
|
|
6
|
-
type MRT_TableInstance,
|
|
7
|
-
} from '../types';
|
|
1
|
+
import { type MRT_Row, type MRT_RowData, type MRT_TableInstance } from '../types';
|
|
8
2
|
import { getMRT_Rows } from '../utils/row.utils';
|
|
9
3
|
|
|
10
|
-
export const useMRT_Rows = <TData extends MRT_RowData>(
|
|
11
|
-
table
|
|
12
|
-
): MRT_Row<TData>[] => {
|
|
13
|
-
const {
|
|
14
|
-
getRowModel,
|
|
15
|
-
options: { data, enableGlobalFilterRankedResults, positionCreatingRow },
|
|
16
|
-
} = table;
|
|
17
|
-
const {
|
|
18
|
-
creatingRow,
|
|
19
|
-
expanded,
|
|
20
|
-
globalFilter,
|
|
21
|
-
pagination,
|
|
22
|
-
rowPinning,
|
|
23
|
-
sorting,
|
|
24
|
-
} = table.state;
|
|
25
|
-
|
|
26
|
-
const rows = useMemo(
|
|
27
|
-
() => getMRT_Rows(table),
|
|
28
|
-
[
|
|
29
|
-
creatingRow,
|
|
30
|
-
data,
|
|
31
|
-
enableGlobalFilterRankedResults,
|
|
32
|
-
expanded,
|
|
33
|
-
getRowModel().rows,
|
|
34
|
-
globalFilter,
|
|
35
|
-
pagination.pageIndex,
|
|
36
|
-
pagination.pageSize,
|
|
37
|
-
positionCreatingRow,
|
|
38
|
-
rowPinning,
|
|
39
|
-
sorting,
|
|
40
|
-
],
|
|
41
|
-
);
|
|
42
|
-
|
|
43
|
-
return rows;
|
|
44
|
-
};
|
|
4
|
+
export const useMRT_Rows = <TData extends MRT_RowData>(table: MRT_TableInstance<TData>): MRT_Row<TData>[] =>
|
|
5
|
+
getMRT_Rows(table);
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { tableFeatures, useTable } from '@tanstack/react-table';
|
|
2
2
|
import { useMemo, useRef, useState } from 'react';
|
|
3
3
|
|
|
4
|
-
import {
|
|
5
|
-
MRT_DefaultTableFeatures,
|
|
6
|
-
type MRT_TableFeatures,
|
|
7
|
-
} from '../fns/tableFeatures';
|
|
4
|
+
import { MRT_DefaultTableFeatures, type MRT_TableFeatures } from '../fns/tableFeatures';
|
|
8
5
|
import {
|
|
9
6
|
type MRT_Cell,
|
|
10
7
|
type MRT_Column,
|
|
@@ -24,12 +21,7 @@ import {
|
|
|
24
21
|
type MRT_TableState,
|
|
25
22
|
type MRT_Updater,
|
|
26
23
|
} from '../types';
|
|
27
|
-
import {
|
|
28
|
-
getAllLeafColumnDefs,
|
|
29
|
-
getColumnId,
|
|
30
|
-
getDefaultColumnFilterFn,
|
|
31
|
-
prepareColumns,
|
|
32
|
-
} from '../utils/column.utils';
|
|
24
|
+
import { getAllLeafColumnDefs, getColumnId, getDefaultColumnFilterFn, prepareColumns } from '../utils/column.utils';
|
|
33
25
|
import {
|
|
34
26
|
getDefaultColumnOrderIds,
|
|
35
27
|
showRowActionsColumn,
|
|
@@ -72,7 +64,7 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
72
64
|
const tableFooterRef = useRef<HTMLTableSectionElement>(null);
|
|
73
65
|
|
|
74
66
|
//transform initial state with proper column order
|
|
75
|
-
const initialState
|
|
67
|
+
const [initialState] = useState<Partial<MRT_TableState<TData>>>(() => {
|
|
76
68
|
const initState = definedTableOptions.initialState ?? {};
|
|
77
69
|
initState.columnOrder =
|
|
78
70
|
initState.columnOrder ??
|
|
@@ -85,83 +77,46 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
85
77
|
} as MRT_StatefulTableOptions<TData>);
|
|
86
78
|
initState.globalFilterFn = definedTableOptions.globalFilterFn ?? 'fuzzy';
|
|
87
79
|
return initState;
|
|
88
|
-
}
|
|
80
|
+
});
|
|
89
81
|
|
|
90
82
|
definedTableOptions.initialState = initialState;
|
|
91
83
|
|
|
92
|
-
const [actionCell, setActionCell] = useState<MRT_Cell<TData> | null>(
|
|
93
|
-
|
|
94
|
-
)
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
).map((col) => ({
|
|
105
|
-
[getColumnId(col)]:
|
|
106
|
-
col.filterFn instanceof Function
|
|
107
|
-
? (col.filterFn.name ?? 'custom')
|
|
108
|
-
: (col.filterFn ??
|
|
109
|
-
initialState?.columnFilterFns?.[getColumnId(col)] ??
|
|
110
|
-
getDefaultColumnFilterFn(col)),
|
|
111
|
-
})),
|
|
112
|
-
),
|
|
113
|
-
);
|
|
114
|
-
const [columnOrder, onColumnOrderChange] = useState<MRT_ColumnOrderState>(
|
|
115
|
-
initialState.columnOrder ?? [],
|
|
116
|
-
);
|
|
117
|
-
const [columnResizing, onColumnResizingChange] =
|
|
118
|
-
useState<MRT_ColumnSizingInfoState>(
|
|
119
|
-
initialState.columnResizing ?? ({} as MRT_ColumnSizingInfoState),
|
|
120
|
-
);
|
|
121
|
-
const [density, setDensity] = useState<MRT_DensityState>(
|
|
122
|
-
initialState?.density ?? 'comfortable',
|
|
123
|
-
);
|
|
124
|
-
const [draggingColumn, setDraggingColumn] =
|
|
125
|
-
useState<MRT_Column<TData> | null>(initialState.draggingColumn ?? null);
|
|
126
|
-
const [draggingRow, setDraggingRow] = useState<MRT_Row<TData> | null>(
|
|
127
|
-
initialState.draggingRow ?? null,
|
|
128
|
-
);
|
|
129
|
-
const [editingCell, setEditingCell] = useState<MRT_Cell<TData> | null>(
|
|
130
|
-
initialState.editingCell ?? null,
|
|
131
|
-
);
|
|
132
|
-
const [editingRow, setEditingRow] = useState<MRT_Row<TData> | null>(
|
|
133
|
-
initialState.editingRow ?? null,
|
|
84
|
+
const [actionCell, setActionCell] = useState<MRT_Cell<TData> | null>(initialState.actionCell ?? null);
|
|
85
|
+
const [creatingRow, _setCreatingRow] = useState<MRT_Row<TData> | null>(initialState.creatingRow ?? null);
|
|
86
|
+
const [columnFilterFns, setColumnFilterFns] = useState<MRT_ColumnFilterFnsState>(() =>
|
|
87
|
+
Object.assign(
|
|
88
|
+
{},
|
|
89
|
+
...getAllLeafColumnDefs(definedTableOptions.columns as MRT_ColumnDef<TData>[]).map((col) => ({
|
|
90
|
+
[getColumnId(col)]:
|
|
91
|
+
col.filterFn instanceof Function
|
|
92
|
+
? (col.filterFn.name ?? 'custom')
|
|
93
|
+
: (col.filterFn ?? initialState?.columnFilterFns?.[getColumnId(col)] ?? getDefaultColumnFilterFn(col)),
|
|
94
|
+
})),
|
|
95
|
+
),
|
|
134
96
|
);
|
|
135
|
-
const [
|
|
136
|
-
|
|
97
|
+
const [columnOrder, onColumnOrderChange] = useState<MRT_ColumnOrderState>(initialState.columnOrder ?? []);
|
|
98
|
+
const [columnResizing, onColumnResizingChange] = useState<MRT_ColumnSizingInfoState>(
|
|
99
|
+
initialState.columnResizing ?? ({} as MRT_ColumnSizingInfoState),
|
|
137
100
|
);
|
|
138
|
-
const [
|
|
139
|
-
|
|
140
|
-
);
|
|
141
|
-
const [
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const [
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
const [isFullScreen, setIsFullScreen] = useState<boolean>(
|
|
148
|
-
initialState?.isFullScreen ?? false,
|
|
101
|
+
const [density, setDensity] = useState<MRT_DensityState>(initialState?.density ?? 'comfortable');
|
|
102
|
+
const [draggingColumn, setDraggingColumn] = useState<MRT_Column<TData> | null>(initialState.draggingColumn ?? null);
|
|
103
|
+
const [draggingRow, setDraggingRow] = useState<MRT_Row<TData> | null>(initialState.draggingRow ?? null);
|
|
104
|
+
const [editingCell, setEditingCell] = useState<MRT_Cell<TData> | null>(initialState.editingCell ?? null);
|
|
105
|
+
const [editingRow, setEditingRow] = useState<MRT_Row<TData> | null>(initialState.editingRow ?? null);
|
|
106
|
+
const [globalFilterFn, setGlobalFilterFn] = useState<MRT_FilterOption>(initialState.globalFilterFn ?? 'fuzzy');
|
|
107
|
+
const [grouping, onGroupingChange] = useState<MRT_GroupingState>(initialState.grouping ?? []);
|
|
108
|
+
const [hoveredColumn, setHoveredColumn] = useState<null | Partial<MRT_Column<TData>>>(
|
|
109
|
+
initialState.hoveredColumn ?? null,
|
|
149
110
|
);
|
|
111
|
+
const [hoveredRow, setHoveredRow] = useState<null | Partial<MRT_Row<TData>>>(initialState.hoveredRow ?? null);
|
|
112
|
+
const [isFullScreen, setIsFullScreen] = useState<boolean>(initialState?.isFullScreen ?? false);
|
|
150
113
|
const [pagination, onPaginationChange] = useState<MRT_PaginationState>(
|
|
151
114
|
initialState?.pagination ?? { pageIndex: 0, pageSize: 10 },
|
|
152
115
|
);
|
|
153
|
-
const [showAlertBanner, setShowAlertBanner] = useState<boolean>(
|
|
154
|
-
|
|
155
|
-
);
|
|
156
|
-
const [
|
|
157
|
-
initialState?.showColumnFilters ?? false,
|
|
158
|
-
);
|
|
159
|
-
const [showGlobalFilter, setShowGlobalFilter] = useState<boolean>(
|
|
160
|
-
initialState?.showGlobalFilter ?? false,
|
|
161
|
-
);
|
|
162
|
-
const [showToolbarDropZone, setShowToolbarDropZone] = useState<boolean>(
|
|
163
|
-
initialState?.showToolbarDropZone ?? false,
|
|
164
|
-
);
|
|
116
|
+
const [showAlertBanner, setShowAlertBanner] = useState<boolean>(initialState?.showAlertBanner ?? false);
|
|
117
|
+
const [showColumnFilters, setShowColumnFilters] = useState<boolean>(initialState?.showColumnFilters ?? false);
|
|
118
|
+
const [showGlobalFilter, setShowGlobalFilter] = useState<boolean>(initialState?.showGlobalFilter ?? false);
|
|
119
|
+
const [showToolbarDropZone, setShowToolbarDropZone] = useState<boolean>(initialState?.showToolbarDropZone ?? false);
|
|
165
120
|
|
|
166
121
|
definedTableOptions.state = {
|
|
167
122
|
actionCell,
|
|
@@ -188,8 +143,7 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
188
143
|
};
|
|
189
144
|
|
|
190
145
|
//The table options now include all state needed to help determine column visibility and order logic
|
|
191
|
-
const statefulTableOptions =
|
|
192
|
-
definedTableOptions as MRT_StatefulTableOptions<TData>;
|
|
146
|
+
const statefulTableOptions = definedTableOptions as MRT_StatefulTableOptions<TData>;
|
|
193
147
|
|
|
194
148
|
//don't recompute columnDefs while resizing column or dragging column/row
|
|
195
149
|
const columnDefsRef = useRef<ReadonlyArray<MRT_ColumnDef<TData>>>([]);
|
|
@@ -201,24 +155,17 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
201
155
|
: prepareColumns({
|
|
202
156
|
columnDefs: [
|
|
203
157
|
...([
|
|
204
|
-
showRowPinningColumn(statefulTableOptions) &&
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
showRowExpandColumn(statefulTableOptions) &&
|
|
211
|
-
getMRT_RowExpandColumnDef(statefulTableOptions),
|
|
212
|
-
showRowSelectionColumn(statefulTableOptions) &&
|
|
213
|
-
getMRT_RowSelectColumnDef(statefulTableOptions),
|
|
214
|
-
showRowNumbersColumn(statefulTableOptions) &&
|
|
215
|
-
getMRT_RowNumbersColumnDef(statefulTableOptions),
|
|
158
|
+
showRowPinningColumn(statefulTableOptions) && getMRT_RowPinningColumnDef(statefulTableOptions),
|
|
159
|
+
showRowDragColumn(statefulTableOptions) && getMRT_RowDragColumnDef(statefulTableOptions),
|
|
160
|
+
showRowActionsColumn(statefulTableOptions) && getMRT_RowActionsColumnDef(statefulTableOptions),
|
|
161
|
+
showRowExpandColumn(statefulTableOptions) && getMRT_RowExpandColumnDef(statefulTableOptions),
|
|
162
|
+
showRowSelectionColumn(statefulTableOptions) && getMRT_RowSelectColumnDef(statefulTableOptions),
|
|
163
|
+
showRowNumbersColumn(statefulTableOptions) && getMRT_RowNumbersColumnDef(statefulTableOptions),
|
|
216
164
|
].filter(Boolean) as MRT_ColumnDef<TData>[]),
|
|
217
165
|
...statefulTableOptions.columns,
|
|
218
|
-
...([
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
].filter(Boolean) as MRT_ColumnDef<TData>[]),
|
|
166
|
+
...([showRowSpacerColumn(statefulTableOptions) && getMRT_RowSpacerColumnDef(statefulTableOptions)].filter(
|
|
167
|
+
Boolean,
|
|
168
|
+
) as MRT_ColumnDef<TData>[]),
|
|
222
169
|
],
|
|
223
170
|
tableOptions: statefulTableOptions,
|
|
224
171
|
});
|
|
@@ -227,27 +174,21 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
227
174
|
//if loading, generate blank rows to show skeleton loaders
|
|
228
175
|
statefulTableOptions.data = useMemo(
|
|
229
176
|
() =>
|
|
230
|
-
(statefulTableOptions.state.isLoading ||
|
|
231
|
-
statefulTableOptions.state.showSkeletons) &&
|
|
177
|
+
(statefulTableOptions.state.isLoading || statefulTableOptions.state.showSkeletons) &&
|
|
232
178
|
!statefulTableOptions.data.length
|
|
233
|
-
? [
|
|
234
|
-
...Array(
|
|
235
|
-
Math.min(statefulTableOptions.state.pagination.pageSize, 20),
|
|
236
|
-
).fill(null),
|
|
237
|
-
].map(() =>
|
|
179
|
+
? [...Array(Math.min(statefulTableOptions.state.pagination.pageSize, 20)).fill(null)].map(() =>
|
|
238
180
|
Object.assign(
|
|
239
181
|
{},
|
|
240
|
-
...getAllLeafColumnDefs(
|
|
241
|
-
(col)
|
|
242
|
-
|
|
243
|
-
}),
|
|
244
|
-
),
|
|
182
|
+
...getAllLeafColumnDefs(columnDefsRef.current).map((col) => ({
|
|
183
|
+
[getColumnId(col)]: null,
|
|
184
|
+
})),
|
|
245
185
|
),
|
|
246
186
|
)
|
|
247
187
|
: statefulTableOptions.data,
|
|
248
188
|
[
|
|
249
189
|
statefulTableOptions.data,
|
|
250
190
|
statefulTableOptions.state.isLoading,
|
|
191
|
+
statefulTableOptions.state.pagination.pageSize,
|
|
251
192
|
statefulTableOptions.state.showSkeletons,
|
|
252
193
|
],
|
|
253
194
|
);
|
|
@@ -301,35 +242,28 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
|
|
|
301
242
|
topToolbarRef,
|
|
302
243
|
},
|
|
303
244
|
setActionCell: statefulTableOptions.onActionCellChange ?? setActionCell,
|
|
304
|
-
setColumnFilterFns:
|
|
305
|
-
statefulTableOptions.onColumnFilterFnsChange ?? setColumnFilterFns,
|
|
245
|
+
setColumnFilterFns: statefulTableOptions.onColumnFilterFnsChange ?? setColumnFilterFns,
|
|
306
246
|
setCreatingRow: (row: MRT_Updater<MRT_Row<TData> | null | true>) => {
|
|
307
247
|
const nextRow = row === true ? createRow(table) : row;
|
|
308
|
-
statefulTableOptions?.onCreatingRowChange?.(
|
|
309
|
-
|
|
310
|
-
|
|
248
|
+
const handled = statefulTableOptions?.onCreatingRowChange?.(nextRow as MRT_Row<TData> | null);
|
|
249
|
+
if (handled === undefined || handled === null) {
|
|
250
|
+
_setCreatingRow(nextRow as MRT_Row<TData> | null);
|
|
251
|
+
}
|
|
311
252
|
},
|
|
312
253
|
setDensity: statefulTableOptions.onDensityChange ?? setDensity,
|
|
313
|
-
setDraggingColumn:
|
|
314
|
-
statefulTableOptions.onDraggingColumnChange ?? setDraggingColumn,
|
|
254
|
+
setDraggingColumn: statefulTableOptions.onDraggingColumnChange ?? setDraggingColumn,
|
|
315
255
|
setDraggingRow: statefulTableOptions.onDraggingRowChange ?? setDraggingRow,
|
|
316
256
|
setEditingCell: statefulTableOptions.onEditingCellChange ?? setEditingCell,
|
|
317
257
|
setEditingRow: statefulTableOptions.onEditingRowChange ?? setEditingRow,
|
|
318
|
-
setGlobalFilterFn:
|
|
319
|
-
|
|
320
|
-
setHoveredColumn:
|
|
321
|
-
statefulTableOptions.onHoveredColumnChange ?? setHoveredColumn,
|
|
258
|
+
setGlobalFilterFn: statefulTableOptions.onGlobalFilterFnChange ?? setGlobalFilterFn,
|
|
259
|
+
setHoveredColumn: statefulTableOptions.onHoveredColumnChange ?? setHoveredColumn,
|
|
322
260
|
setHoveredRow: statefulTableOptions.onHoveredRowChange ?? setHoveredRow,
|
|
323
261
|
setIsFullScreen: statefulTableOptions.onIsFullScreenChange ?? setIsFullScreen,
|
|
324
|
-
setShowAlertBanner:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
statefulTableOptions.onShowGlobalFilterChange ?? setShowGlobalFilter,
|
|
330
|
-
setShowToolbarDropZone:
|
|
331
|
-
statefulTableOptions.onShowToolbarDropZoneChange ?? setShowToolbarDropZone,
|
|
332
|
-
});
|
|
262
|
+
setShowAlertBanner: statefulTableOptions.onShowAlertBannerChange ?? setShowAlertBanner,
|
|
263
|
+
setShowColumnFilters: statefulTableOptions.onShowColumnFiltersChange ?? setShowColumnFilters,
|
|
264
|
+
setShowGlobalFilter: statefulTableOptions.onShowGlobalFilterChange ?? setShowGlobalFilter,
|
|
265
|
+
setShowToolbarDropZone: statefulTableOptions.onShowToolbarDropZoneChange ?? setShowToolbarDropZone,
|
|
266
|
+
}) as MRT_TableInstance<TData>;
|
|
333
267
|
|
|
334
268
|
useMRT_Effects(table);
|
|
335
269
|
|
|
@@ -1,16 +1,12 @@
|
|
|
1
1
|
import { useTheme } from '@mui/material/styles';
|
|
2
|
-
import { useId, useMemo } from 'react';
|
|
2
|
+
import { useId, useMemo, useState } from 'react';
|
|
3
3
|
|
|
4
4
|
import { MRT_AggregationFns } from '../fns/aggregationFns';
|
|
5
5
|
import { MRT_FilterFns } from '../fns/filterFns';
|
|
6
6
|
import { MRT_SortingFns } from '../fns/sortingFns';
|
|
7
7
|
import { MRT_Default_Icons } from '../icons';
|
|
8
8
|
import { MRT_Localization_EN } from '../locales/en';
|
|
9
|
-
import {
|
|
10
|
-
type MRT_DefinedTableOptions,
|
|
11
|
-
type MRT_RowData,
|
|
12
|
-
type MRT_TableOptions,
|
|
13
|
-
} from '../types';
|
|
9
|
+
import { type MRT_DefinedTableOptions, type MRT_RowData, type MRT_TableOptions } from '../types';
|
|
14
10
|
import { getMRTTheme } from '../utils/style.utils';
|
|
15
11
|
|
|
16
12
|
export const MRT_DefaultColumn = {
|
|
@@ -115,16 +111,11 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
|
115
111
|
[localization],
|
|
116
112
|
);
|
|
117
113
|
mrtTheme = useMemo(() => getMRTTheme(mrtTheme, theme), [mrtTheme, theme]);
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
);
|
|
122
|
-
|
|
123
|
-
sortFns = useMemo(() => ({ ...MRT_SortingFns, ...sortFns }), []);
|
|
124
|
-
defaultColumn = useMemo(
|
|
125
|
-
() => ({ ...MRT_DefaultColumn, ...defaultColumn }),
|
|
126
|
-
[defaultColumn],
|
|
127
|
-
);
|
|
114
|
+
//cannot be changed after initialization
|
|
115
|
+
[aggregationFns] = useState(() => ({ ...MRT_AggregationFns, ...aggregationFns }));
|
|
116
|
+
[filterFns] = useState(() => ({ ...MRT_FilterFns, ...filterFns }));
|
|
117
|
+
[sortFns] = useState(() => ({ ...MRT_SortingFns, ...sortFns }));
|
|
118
|
+
defaultColumn = useMemo(() => ({ ...MRT_DefaultColumn, ...defaultColumn }), [defaultColumn]);
|
|
128
119
|
defaultDisplayColumn = useMemo(
|
|
129
120
|
() => ({
|
|
130
121
|
...MRT_DefaultDisplayColumn,
|
|
@@ -133,21 +124,17 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
|
133
124
|
[defaultDisplayColumn],
|
|
134
125
|
);
|
|
135
126
|
//cannot be changed after initialization
|
|
136
|
-
[enableColumnVirtualization, enableRowVirtualization] =
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
);
|
|
127
|
+
[[enableColumnVirtualization, enableRowVirtualization]] = useState(() => [
|
|
128
|
+
enableColumnVirtualization,
|
|
129
|
+
enableRowVirtualization,
|
|
130
|
+
]);
|
|
140
131
|
|
|
141
132
|
if (!columnResizeDirection) {
|
|
142
133
|
columnResizeDirection = theme.direction || 'ltr';
|
|
143
134
|
}
|
|
144
135
|
|
|
145
|
-
layoutMode =
|
|
146
|
-
|
|
147
|
-
if (
|
|
148
|
-
layoutMode === 'semantic' &&
|
|
149
|
-
(enableRowVirtualization || enableColumnVirtualization)
|
|
150
|
-
) {
|
|
136
|
+
layoutMode = layoutMode || (enableColumnResizing ? 'grid-no-grow' : 'semantic');
|
|
137
|
+
if (layoutMode === 'semantic' && (enableRowVirtualization || enableColumnVirtualization)) {
|
|
151
138
|
layoutMode = 'grid';
|
|
152
139
|
}
|
|
153
140
|
|
|
@@ -210,9 +197,8 @@ export const useMRT_TableOptions: <TData extends MRT_RowData>(
|
|
|
210
197
|
enableToolbarInternalActions,
|
|
211
198
|
enableTopToolbar,
|
|
212
199
|
filterFns,
|
|
213
|
-
getRowCanExpand:
|
|
214
|
-
|
|
215
|
-
getSubRows: (row) => row?.subRows,
|
|
200
|
+
getRowCanExpand: rest.getRowCanExpand ?? (rest.renderDetailPanel ? () => true : undefined),
|
|
201
|
+
getSubRows: (row) => ('subRows' in row ? (row.subRows as TData[] | undefined) : undefined),
|
|
216
202
|
icons,
|
|
217
203
|
id,
|
|
218
204
|
layoutMode,
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type MRT_RowData,
|
|
3
|
-
type MRT_TableInstance,
|
|
4
|
-
type MRT_TableOptions,
|
|
5
|
-
} from '../types';
|
|
1
|
+
import { type MRT_RowData, type MRT_TableInstance, type MRT_TableOptions } from '../types';
|
|
6
2
|
import { useMRT_TableInstance } from './useMRT_TableInstance';
|
|
7
3
|
import { useMRT_TableOptions } from './useMRT_TableOptions';
|
|
8
4
|
|
|
9
5
|
export const useMaterialReactTable = <TData extends MRT_RowData>(
|
|
10
6
|
tableOptions: MRT_TableOptions<TData>,
|
|
11
|
-
): MRT_TableInstance<TData> =>
|
|
12
|
-
useMRT_TableInstance(useMRT_TableOptions(tableOptions));
|
|
7
|
+
): MRT_TableInstance<TData> => useMRT_TableInstance(useMRT_TableOptions(tableOptions));
|