material-react-table 2.7.0 → 2.8.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/index.d.ts +239 -93
- package/dist/index.esm.js +3489 -3470
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +3486 -3470
- package/dist/index.js.map +1 -1
- package/package.json +20 -20
- package/src/{MaterialReactTable.tsx → components/MaterialReactTable.tsx} +3 -3
- package/src/{body → components/body}/MRT_TableBody.tsx +4 -4
- package/src/{body → components/body}/MRT_TableBodyCell.tsx +6 -23
- package/src/{body → components/body}/MRT_TableBodyCellValue.tsx +2 -2
- package/src/{body → components/body}/MRT_TableBodyRow.tsx +3 -3
- package/src/{body → components/body}/MRT_TableBodyRowGrabHandle.tsx +3 -3
- package/src/{body → components/body}/MRT_TableBodyRowPinButton.tsx +3 -3
- package/src/{body → components/body}/MRT_TableDetailPanel.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ColumnPinningButtons.tsx +2 -2
- package/src/{buttons → components/buttons}/MRT_CopyButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_EditActionButtons.tsx +2 -2
- package/src/{buttons → components/buttons}/MRT_ExpandAllButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ExpandButton.tsx +6 -3
- package/src/{buttons → components/buttons}/MRT_GrabHandleButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_RowPinButton.tsx +3 -3
- package/src/{buttons → components/buttons}/MRT_ShowHideColumnsButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleDensePaddingButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleFiltersButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleFullScreenButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleGlobalFilterButton.tsx +1 -1
- package/src/{buttons → components/buttons}/MRT_ToggleRowActionMenuButton.tsx +4 -4
- package/src/{footer → components/footer}/MRT_TableFooter.tsx +2 -2
- package/src/{footer → components/footer}/MRT_TableFooterCell.tsx +3 -3
- package/src/{footer → components/footer}/MRT_TableFooterRow.tsx +3 -3
- package/src/{head → components/head}/MRT_TableHead.tsx +3 -3
- package/src/{head → components/head}/MRT_TableHeadCell.tsx +3 -3
- package/src/{head → components/head}/MRT_TableHeadCellColumnActionsButton.tsx +4 -4
- package/src/{head → components/head}/MRT_TableHeadCellFilterContainer.tsx +5 -5
- package/src/{head → components/head}/MRT_TableHeadCellFilterLabel.tsx +2 -2
- package/src/{head → components/head}/MRT_TableHeadCellGrabHandle.tsx +4 -3
- package/src/{head → components/head}/MRT_TableHeadCellResizeHandle.tsx +2 -2
- package/src/{head → components/head}/MRT_TableHeadCellSortLabel.tsx +2 -2
- package/src/{head → components/head}/MRT_TableHeadRow.tsx +3 -3
- package/src/{inputs → components/inputs}/MRT_EditCellTextField.tsx +12 -4
- package/src/{inputs → components/inputs}/MRT_FilterCheckbox.tsx +3 -3
- package/src/{inputs → components/inputs}/MRT_FilterRangeFields.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_FilterRangeSlider.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_FilterTextField.tsx +3 -3
- package/src/{inputs → components/inputs}/MRT_GlobalFilterTextField.tsx +2 -2
- package/src/{inputs → components/inputs}/MRT_SelectCheckbox.tsx +3 -3
- package/src/{menus → components/menus}/MRT_ColumnActionMenu.tsx +8 -8
- package/src/{menus → components/menus}/MRT_FilterOptionMenu.tsx +2 -2
- package/src/{menus → components/menus}/MRT_RowActionMenu.tsx +9 -9
- package/src/{menus → components/menus}/MRT_ShowHideColumnsMenu.tsx +5 -7
- package/src/{menus → components/menus}/MRT_ShowHideColumnsMenuItems.tsx +6 -5
- package/src/{modals → components/modals}/MRT_EditRowModal.tsx +4 -4
- package/src/{table → components/table}/MRT_Table.tsx +4 -4
- package/src/{table → components/table}/MRT_TableContainer.tsx +2 -2
- package/src/{table → components/table}/MRT_TableLoadingOverlay.tsx +3 -3
- package/src/{table → components/table}/MRT_TablePaper.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_BottomToolbar.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_LinearProgressBar.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_TablePagination.tsx +3 -3
- package/src/{toolbar → components/toolbar}/MRT_ToolbarAlertBanner.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_ToolbarDropZone.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_ToolbarInternalButtons.tsx +2 -2
- package/src/{toolbar → components/toolbar}/MRT_TopToolbar.tsx +3 -3
- package/src/{filterFns.ts → fns/filterFns.ts} +1 -1
- package/src/{sortingFns.ts → fns/sortingFns.ts} +1 -1
- package/src/hooks/display-columns/getMRT_DisplayColumns.tsx +26 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +34 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +35 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +96 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +36 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +30 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +40 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +40 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +2 -4
- package/src/hooks/useMRT_Effects.ts +1 -1
- package/src/hooks/useMRT_RowVirtualizer.ts +2 -4
- package/src/hooks/useMRT_Rows.ts +2 -2
- package/src/hooks/useMRT_TableInstance.ts +54 -39
- package/src/hooks/useMRT_TableOptions.ts +3 -3
- package/src/{useMaterialReactTable.ts → hooks/useMaterialReactTable.ts} +3 -3
- package/src/index.ts +79 -82
- package/src/types.ts +54 -26
- package/src/utils/column.utils.ts +173 -0
- package/src/utils/displayColumn.utils.ts +134 -0
- package/src/utils/row.utils.ts +26 -0
- package/src/{style.utils.ts → utils/style.utils.ts} +21 -15
- package/src/utils/tanstack.helpers.ts +64 -0
- package/src/utils/utils.ts +23 -0
- package/src/utils/virtualization.utils.ts +19 -0
- package/src/utils.ts +0 -0
- package/src/column.utils.ts +0 -361
- package/src/hooks/useMRT_DisplayColumns.tsx +0 -290
- /package/src/{aggregationFns.ts → fns/aggregationFns.ts} +0 -0
package/src/index.ts
CHANGED
@@ -1,92 +1,89 @@
|
|
1
|
-
//root
|
2
|
-
export * from './MaterialReactTable';
|
3
|
-
export * from './aggregationFns';
|
4
|
-
export * from './column.utils';
|
5
|
-
export * from './filterFns';
|
6
|
-
export * from './sortingFns';
|
7
|
-
export * from './style.utils';
|
8
1
|
export * from './types';
|
9
|
-
|
2
|
+
|
3
|
+
//helpers
|
4
|
+
export * from './utils/tanstack.helpers';
|
5
|
+
export * from './utils/column.utils';
|
6
|
+
export * from './utils/displayColumn.utils';
|
7
|
+
export * from './utils/row.utils';
|
8
|
+
|
9
|
+
//fns
|
10
|
+
export * from './fns/aggregationFns';
|
11
|
+
export * from './fns/filterFns';
|
12
|
+
export * from './fns/sortingFns';
|
10
13
|
|
11
14
|
//hooks
|
15
|
+
export * from './hooks/useMaterialReactTable';
|
12
16
|
export * from './hooks/useMRT_ColumnVirtualizer';
|
13
|
-
export * from './hooks/useMRT_DisplayColumns';
|
14
17
|
export * from './hooks/useMRT_Effects';
|
15
18
|
export * from './hooks/useMRT_RowVirtualizer';
|
16
19
|
export * from './hooks/useMRT_Rows';
|
17
20
|
export * from './hooks/useMRT_TableInstance';
|
18
21
|
export * from './hooks/useMRT_TableOptions';
|
19
22
|
|
20
|
-
//
|
21
|
-
export * from './
|
22
|
-
|
23
|
-
export * from './body/
|
24
|
-
export * from './body/
|
25
|
-
export * from './body/
|
26
|
-
export * from './body/
|
27
|
-
export * from './body/
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
export * from './buttons/
|
32
|
-
export * from './buttons/
|
33
|
-
export * from './buttons/
|
34
|
-
export * from './buttons/
|
35
|
-
export * from './buttons/
|
36
|
-
export * from './buttons/
|
37
|
-
export * from './buttons/
|
38
|
-
export * from './buttons/
|
39
|
-
export * from './buttons/
|
40
|
-
export * from './buttons/
|
41
|
-
export * from './buttons/
|
42
|
-
export * from './buttons/
|
43
|
-
|
44
|
-
//footer
|
45
|
-
export * from './footer/MRT_TableFooter';
|
46
|
-
export * from './footer/MRT_TableFooterCell';
|
47
|
-
export * from './footer/MRT_TableFooterRow';
|
48
|
-
|
49
|
-
|
50
|
-
export * from './head/
|
51
|
-
export * from './head/
|
52
|
-
export * from './head/
|
53
|
-
export * from './head/
|
54
|
-
export * from './head/
|
55
|
-
export * from './head/
|
56
|
-
export * from './head/
|
57
|
-
export * from './head/
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
export * from './inputs/
|
62
|
-
export * from './inputs/
|
63
|
-
export * from './inputs/
|
64
|
-
export * from './inputs/
|
65
|
-
export * from './inputs/
|
66
|
-
|
67
|
-
export * from './
|
68
|
-
|
69
|
-
|
70
|
-
export * from './menus/
|
71
|
-
export * from './menus/
|
72
|
-
|
73
|
-
export * from './
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
export * from './
|
78
|
-
|
79
|
-
//
|
80
|
-
export * from './
|
81
|
-
export * from './
|
82
|
-
export * from './
|
83
|
-
export * from './
|
84
|
-
|
85
|
-
|
86
|
-
export * from './toolbar/
|
87
|
-
export * from './toolbar/MRT_LinearProgressBar';
|
88
|
-
export * from './toolbar/MRT_TablePagination';
|
89
|
-
export * from './toolbar/MRT_ToolbarAlertBanner';
|
90
|
-
export * from './toolbar/MRT_ToolbarDropZone';
|
91
|
-
export * from './toolbar/MRT_ToolbarInternalButtons';
|
92
|
-
export * from './toolbar/MRT_TopToolbar';
|
23
|
+
//components
|
24
|
+
export * from './components/MaterialReactTable';
|
25
|
+
//body components
|
26
|
+
export * from './components/body/MRT_TableBody';
|
27
|
+
export * from './components/body/MRT_TableBodyCell';
|
28
|
+
export * from './components/body/MRT_TableBodyCellValue';
|
29
|
+
export * from './components/body/MRT_TableBodyRow';
|
30
|
+
export * from './components/body/MRT_TableBodyRowGrabHandle';
|
31
|
+
export * from './components/body/MRT_TableBodyRowPinButton';
|
32
|
+
export * from './components/body/MRT_TableDetailPanel';
|
33
|
+
//button components
|
34
|
+
export * from './components/buttons/MRT_ColumnPinningButtons';
|
35
|
+
export * from './components/buttons/MRT_CopyButton';
|
36
|
+
export * from './components/buttons/MRT_EditActionButtons';
|
37
|
+
export * from './components/buttons/MRT_ExpandAllButton';
|
38
|
+
export * from './components/buttons/MRT_ExpandButton';
|
39
|
+
export * from './components/buttons/MRT_GrabHandleButton';
|
40
|
+
export * from './components/buttons/MRT_RowPinButton';
|
41
|
+
export * from './components/buttons/MRT_ShowHideColumnsButton';
|
42
|
+
export * from './components/buttons/MRT_ToggleDensePaddingButton';
|
43
|
+
export * from './components/buttons/MRT_ToggleFiltersButton';
|
44
|
+
export * from './components/buttons/MRT_ToggleFullScreenButton';
|
45
|
+
export * from './components/buttons/MRT_ToggleGlobalFilterButton';
|
46
|
+
export * from './components/buttons/MRT_ToggleRowActionMenuButton';
|
47
|
+
//footer components
|
48
|
+
export * from './components/footer/MRT_TableFooter';
|
49
|
+
export * from './components/footer/MRT_TableFooterCell';
|
50
|
+
export * from './components/footer/MRT_TableFooterRow';
|
51
|
+
//head components
|
52
|
+
export * from './components/head/MRT_TableHead';
|
53
|
+
export * from './components/head/MRT_TableHeadCell';
|
54
|
+
export * from './components/head/MRT_TableHeadCellColumnActionsButton';
|
55
|
+
export * from './components/head/MRT_TableHeadCellFilterContainer';
|
56
|
+
export * from './components/head/MRT_TableHeadCellFilterLabel';
|
57
|
+
export * from './components/head/MRT_TableHeadCellGrabHandle';
|
58
|
+
export * from './components/head/MRT_TableHeadCellResizeHandle';
|
59
|
+
export * from './components/head/MRT_TableHeadCellSortLabel';
|
60
|
+
export * from './components/head/MRT_TableHeadRow';
|
61
|
+
//input components
|
62
|
+
export * from './components/inputs/MRT_EditCellTextField';
|
63
|
+
export * from './components/inputs/MRT_FilterCheckbox';
|
64
|
+
export * from './components/inputs/MRT_FilterRangeFields';
|
65
|
+
export * from './components/inputs/MRT_FilterRangeSlider';
|
66
|
+
export * from './components/inputs/MRT_FilterTextField';
|
67
|
+
export * from './components/inputs/MRT_GlobalFilterTextField';
|
68
|
+
export * from './components/inputs/MRT_SelectCheckbox';
|
69
|
+
//menu components
|
70
|
+
export * from './components/menus/MRT_ColumnActionMenu';
|
71
|
+
export * from './components/menus/MRT_FilterOptionMenu';
|
72
|
+
export * from './components/menus/MRT_RowActionMenu';
|
73
|
+
export * from './components/menus/MRT_ShowHideColumnsMenu';
|
74
|
+
export * from './components/menus/MRT_ShowHideColumnsMenuItems';
|
75
|
+
//modal components
|
76
|
+
export * from './components/modals/MRT_EditRowModal';
|
77
|
+
//table components
|
78
|
+
export * from './components/table/MRT_Table';
|
79
|
+
export * from './components/table/MRT_TableContainer';
|
80
|
+
export * from './components/table/MRT_TableLoadingOverlay';
|
81
|
+
export * from './components/table/MRT_TablePaper';
|
82
|
+
//toolbar components
|
83
|
+
export * from './components/toolbar/MRT_BottomToolbar';
|
84
|
+
export * from './components/toolbar/MRT_LinearProgressBar';
|
85
|
+
export * from './components/toolbar/MRT_TablePagination';
|
86
|
+
export * from './components/toolbar/MRT_ToolbarAlertBanner';
|
87
|
+
export * from './components/toolbar/MRT_ToolbarDropZone';
|
88
|
+
export * from './components/toolbar/MRT_ToolbarInternalButtons';
|
89
|
+
export * from './components/toolbar/MRT_TopToolbar';
|
package/src/types.ts
CHANGED
@@ -71,10 +71,10 @@ import {
|
|
71
71
|
type DateTimePickerProps,
|
72
72
|
type TimePickerProps,
|
73
73
|
} from '@mui/x-date-pickers';
|
74
|
-
import { type MRT_AggregationFns } from './aggregationFns';
|
75
|
-
import { type MRT_FilterFns } from './filterFns';
|
74
|
+
import { type MRT_AggregationFns } from './fns/aggregationFns';
|
75
|
+
import { type MRT_FilterFns } from './fns/filterFns';
|
76
|
+
import { type MRT_SortingFns } from './fns/sortingFns';
|
76
77
|
import { type MRT_Icons } from './icons';
|
77
|
-
import { type MRT_SortingFns } from './sortingFns';
|
78
78
|
|
79
79
|
export type { MRT_Icons };
|
80
80
|
export type LiteralUnion<T extends U, U = string> =
|
@@ -87,6 +87,17 @@ export type Xor<A, B> =
|
|
87
87
|
| Prettify<A & { [k in keyof B]?: never }>
|
88
88
|
| Prettify<B & { [k in keyof A]?: never }>;
|
89
89
|
|
90
|
+
export type DropdownOption =
|
91
|
+
| {
|
92
|
+
label?: string;
|
93
|
+
/**
|
94
|
+
* @deprecated use `label` instead
|
95
|
+
*/
|
96
|
+
text?: string;
|
97
|
+
value: any;
|
98
|
+
}
|
99
|
+
| string;
|
100
|
+
|
90
101
|
export type MRT_DensityState = 'comfortable' | 'compact' | 'spacious';
|
91
102
|
|
92
103
|
export type MRT_ColumnFilterFnsState = Record<string, MRT_FilterOption>;
|
@@ -302,7 +313,7 @@ export type MRT_TableInstance<TData extends MRT_RowData> = Omit<
|
|
302
313
|
getSelectedRowModel: () => MRT_RowModel<TData>;
|
303
314
|
getState: () => MRT_TableState<TData>;
|
304
315
|
getTopRows: () => MRT_Row<TData>[];
|
305
|
-
options:
|
316
|
+
options: MRT_StatefulTableOptions<TData>;
|
306
317
|
refs: {
|
307
318
|
bottomToolbarRef: MutableRefObject<HTMLDivElement>;
|
308
319
|
editInputRefs: MutableRefObject<Record<string, HTMLInputElement>>;
|
@@ -338,6 +349,32 @@ export type MRT_DefinedTableOptions<TData extends MRT_RowData> =
|
|
338
349
|
localization: MRT_Localization;
|
339
350
|
};
|
340
351
|
|
352
|
+
export type MRT_StatefulTableOptions<TData extends MRT_RowData> =
|
353
|
+
MRT_DefinedTableOptions<TData> & {
|
354
|
+
state: Pick<
|
355
|
+
MRT_TableState<TData>,
|
356
|
+
| 'columnFilterFns'
|
357
|
+
| 'columnOrder'
|
358
|
+
| 'columnSizingInfo'
|
359
|
+
| 'creatingRow'
|
360
|
+
| 'density'
|
361
|
+
| 'draggingColumn'
|
362
|
+
| 'draggingRow'
|
363
|
+
| 'editingCell'
|
364
|
+
| 'editingRow'
|
365
|
+
| 'globalFilterFn'
|
366
|
+
| 'grouping'
|
367
|
+
| 'hoveredColumn'
|
368
|
+
| 'hoveredRow'
|
369
|
+
| 'isFullScreen'
|
370
|
+
| 'pagination'
|
371
|
+
| 'showAlertBanner'
|
372
|
+
| 'showColumnFilters'
|
373
|
+
| 'showGlobalFilter'
|
374
|
+
| 'showToolbarDropZone'
|
375
|
+
>;
|
376
|
+
};
|
377
|
+
|
341
378
|
export type MRT_TableState<TData extends MRT_RowData> = TableState & {
|
342
379
|
columnFilterFns: MRT_ColumnFilterFnsState;
|
343
380
|
creatingRow: MRT_Row<TData> | null;
|
@@ -457,17 +494,14 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
457
494
|
LiteralUnion<string & MRT_FilterOption>
|
458
495
|
> | null;
|
459
496
|
columns?: MRT_ColumnDef<TData, TValue>[];
|
460
|
-
editSelectOptions?:
|
461
|
-
| {
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
}
|
469
|
-
| string
|
470
|
-
)[];
|
497
|
+
editSelectOptions?:
|
498
|
+
| ((props: {
|
499
|
+
cell: MRT_Cell<TData, TValue>;
|
500
|
+
column: MRT_Column<TData>;
|
501
|
+
row: MRT_Row<TData>;
|
502
|
+
table: MRT_TableInstance<TData>;
|
503
|
+
}) => DropdownOption[])
|
504
|
+
| DropdownOption[];
|
471
505
|
editVariant?: 'select' | 'text';
|
472
506
|
enableClickToCopy?: boolean;
|
473
507
|
enableColumnActions?: boolean;
|
@@ -477,17 +511,7 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
477
511
|
enableEditing?: ((row: MRT_Row<TData>) => boolean) | boolean;
|
478
512
|
enableFilterMatchHighlighting?: boolean;
|
479
513
|
filterFn?: MRT_FilterFn<TData>;
|
480
|
-
filterSelectOptions?:
|
481
|
-
| {
|
482
|
-
label?: string;
|
483
|
-
/**
|
484
|
-
* @deprecated use `label` instead
|
485
|
-
*/
|
486
|
-
text?: string;
|
487
|
-
value: any;
|
488
|
-
}
|
489
|
-
| string
|
490
|
-
)[];
|
514
|
+
filterSelectOptions?: DropdownOption[];
|
491
515
|
filterVariant?:
|
492
516
|
| 'autocomplete'
|
493
517
|
| 'checkbox'
|
@@ -506,6 +530,10 @@ export type MRT_ColumnDef<TData extends MRT_RowData, TValue = unknown> = Omit<
|
|
506
530
|
* footer must be a string. If you want custom JSX to render the footer, you can also specify a `Footer` option. (Capital F)
|
507
531
|
*/
|
508
532
|
footer?: string;
|
533
|
+
/**
|
534
|
+
* If `layoutMode` is `'grid'` or `'grid-no-grow'`, you can specify the flex grow value for individual columns to still grow and take up remaining space, or set to `false`/0 to not grow.
|
535
|
+
*/
|
536
|
+
grow?: boolean | number;
|
509
537
|
/**
|
510
538
|
* header must be a string. If you want custom JSX to render the header, you can also specify a `Header` option. (Capital H)
|
511
539
|
*/
|
@@ -0,0 +1,173 @@
|
|
1
|
+
import { type Row } from '@tanstack/react-table';
|
2
|
+
import {
|
3
|
+
type MRT_Column,
|
4
|
+
type MRT_ColumnDef,
|
5
|
+
type MRT_ColumnOrderState,
|
6
|
+
type MRT_DefinedColumnDef,
|
7
|
+
type MRT_DefinedTableOptions,
|
8
|
+
type MRT_FilterOption,
|
9
|
+
type MRT_RowData,
|
10
|
+
type MRT_TableInstance,
|
11
|
+
} from '../types';
|
12
|
+
|
13
|
+
export const getColumnId = <TData extends MRT_RowData>(
|
14
|
+
columnDef: MRT_ColumnDef<TData>,
|
15
|
+
): string =>
|
16
|
+
columnDef.id ?? columnDef.accessorKey?.toString?.() ?? columnDef.header;
|
17
|
+
|
18
|
+
export const getAllLeafColumnDefs = <TData extends MRT_RowData>(
|
19
|
+
columns: MRT_ColumnDef<TData>[],
|
20
|
+
): MRT_ColumnDef<TData>[] => {
|
21
|
+
const allLeafColumnDefs: MRT_ColumnDef<TData>[] = [];
|
22
|
+
const getLeafColumns = (cols: MRT_ColumnDef<TData>[]) => {
|
23
|
+
cols.forEach((col) => {
|
24
|
+
if (col.columns) {
|
25
|
+
getLeafColumns(col.columns);
|
26
|
+
} else {
|
27
|
+
allLeafColumnDefs.push(col);
|
28
|
+
}
|
29
|
+
});
|
30
|
+
};
|
31
|
+
getLeafColumns(columns);
|
32
|
+
return allLeafColumnDefs;
|
33
|
+
};
|
34
|
+
|
35
|
+
export const prepareColumns = <TData extends MRT_RowData>({
|
36
|
+
columnDefs,
|
37
|
+
tableOptions,
|
38
|
+
}: {
|
39
|
+
columnDefs: MRT_ColumnDef<TData>[];
|
40
|
+
tableOptions: MRT_DefinedTableOptions<TData>;
|
41
|
+
}): MRT_DefinedColumnDef<TData>[] => {
|
42
|
+
const {
|
43
|
+
aggregationFns = {},
|
44
|
+
defaultDisplayColumn,
|
45
|
+
filterFns = {},
|
46
|
+
sortingFns = {},
|
47
|
+
state: { columnFilterFns = {} } = {},
|
48
|
+
} = tableOptions;
|
49
|
+
return columnDefs.map((columnDef) => {
|
50
|
+
//assign columnId
|
51
|
+
if (!columnDef.id) columnDef.id = getColumnId(columnDef);
|
52
|
+
//assign columnDefType
|
53
|
+
if (!columnDef.columnDefType) columnDef.columnDefType = 'data';
|
54
|
+
if (columnDef.columns?.length) {
|
55
|
+
columnDef.columnDefType = 'group';
|
56
|
+
//recursively prepare columns if this is a group column
|
57
|
+
columnDef.columns = prepareColumns({
|
58
|
+
columnDefs: columnDef.columns,
|
59
|
+
tableOptions,
|
60
|
+
});
|
61
|
+
} else if (columnDef.columnDefType === 'data') {
|
62
|
+
//assign aggregationFns if multiple aggregationFns are provided
|
63
|
+
if (Array.isArray(columnDef.aggregationFn)) {
|
64
|
+
const aggFns = columnDef.aggregationFn as string[];
|
65
|
+
columnDef.aggregationFn = (
|
66
|
+
columnId: string,
|
67
|
+
leafRows: Row<TData>[],
|
68
|
+
childRows: Row<TData>[],
|
69
|
+
) =>
|
70
|
+
aggFns.map((fn) =>
|
71
|
+
aggregationFns[fn]?.(columnId, leafRows, childRows),
|
72
|
+
);
|
73
|
+
}
|
74
|
+
|
75
|
+
//assign filterFns
|
76
|
+
if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
|
77
|
+
columnDef.filterFn =
|
78
|
+
filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
|
79
|
+
(columnDef as MRT_DefinedColumnDef<TData>)._filterFn =
|
80
|
+
columnFilterFns[columnDef.id];
|
81
|
+
}
|
82
|
+
|
83
|
+
//assign sortingFns
|
84
|
+
if (Object.keys(sortingFns).includes(columnDef.sortingFn as string)) {
|
85
|
+
// @ts-ignore
|
86
|
+
columnDef.sortingFn = sortingFns[columnDef.sortingFn];
|
87
|
+
}
|
88
|
+
} else if (columnDef.columnDefType === 'display') {
|
89
|
+
columnDef = {
|
90
|
+
...(defaultDisplayColumn as MRT_ColumnDef<TData>),
|
91
|
+
...columnDef,
|
92
|
+
};
|
93
|
+
}
|
94
|
+
return columnDef;
|
95
|
+
}) as MRT_DefinedColumnDef<TData>[];
|
96
|
+
};
|
97
|
+
|
98
|
+
export const reorderColumn = <TData extends MRT_RowData>(
|
99
|
+
draggedColumn: MRT_Column<TData>,
|
100
|
+
targetColumn: MRT_Column<TData>,
|
101
|
+
columnOrder: MRT_ColumnOrderState,
|
102
|
+
): MRT_ColumnOrderState => {
|
103
|
+
if (draggedColumn.getCanPin()) {
|
104
|
+
draggedColumn.pin(targetColumn.getIsPinned());
|
105
|
+
}
|
106
|
+
const newColumnOrder = [...columnOrder];
|
107
|
+
newColumnOrder.splice(
|
108
|
+
newColumnOrder.indexOf(targetColumn.id),
|
109
|
+
0,
|
110
|
+
newColumnOrder.splice(newColumnOrder.indexOf(draggedColumn.id), 1)[0],
|
111
|
+
);
|
112
|
+
return newColumnOrder;
|
113
|
+
};
|
114
|
+
|
115
|
+
export const getDefaultColumnFilterFn = <TData extends MRT_RowData>(
|
116
|
+
columnDef: MRT_ColumnDef<TData>,
|
117
|
+
): MRT_FilterOption => {
|
118
|
+
if (columnDef.filterVariant === 'multi-select') return 'arrIncludesSome';
|
119
|
+
if (columnDef.filterVariant?.includes('range')) return 'betweenInclusive';
|
120
|
+
if (
|
121
|
+
columnDef.filterVariant === 'select' ||
|
122
|
+
columnDef.filterVariant === 'checkbox'
|
123
|
+
)
|
124
|
+
return 'equals';
|
125
|
+
return 'fuzzy';
|
126
|
+
};
|
127
|
+
|
128
|
+
export const getIsFirstColumn = <TData extends MRT_RowData>(
|
129
|
+
column: MRT_Column<TData>,
|
130
|
+
table: MRT_TableInstance<TData>,
|
131
|
+
) => {
|
132
|
+
const leftColumns = table.getLeftVisibleLeafColumns();
|
133
|
+
return leftColumns.length
|
134
|
+
? leftColumns[0].id === column.id
|
135
|
+
: table.getVisibleLeafColumns()[0].id === column.id;
|
136
|
+
};
|
137
|
+
|
138
|
+
export const getIsLastColumn = <TData extends MRT_RowData>(
|
139
|
+
column: MRT_Column<TData>,
|
140
|
+
table: MRT_TableInstance<TData>,
|
141
|
+
) => {
|
142
|
+
const rightColumns = table.getRightVisibleLeafColumns();
|
143
|
+
const columns = table.getVisibleLeafColumns();
|
144
|
+
return rightColumns.length
|
145
|
+
? rightColumns[rightColumns.length - 1].id === column.id
|
146
|
+
: columns[columns.length - 1].id === column.id;
|
147
|
+
};
|
148
|
+
|
149
|
+
export const getIsLastLeftPinnedColumn = <TData extends MRT_RowData>(
|
150
|
+
table: MRT_TableInstance<TData>,
|
151
|
+
column: MRT_Column<TData>,
|
152
|
+
) => {
|
153
|
+
return (
|
154
|
+
column.getIsPinned() === 'left' &&
|
155
|
+
table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
156
|
+
);
|
157
|
+
};
|
158
|
+
|
159
|
+
export const getIsFirstRightPinnedColumn = <TData extends MRT_RowData>(
|
160
|
+
column: MRT_Column<TData>,
|
161
|
+
) => {
|
162
|
+
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
163
|
+
};
|
164
|
+
|
165
|
+
export const getTotalRight = <TData extends MRT_RowData>(
|
166
|
+
table: MRT_TableInstance<TData>,
|
167
|
+
column: MRT_Column<TData>,
|
168
|
+
) => {
|
169
|
+
return table
|
170
|
+
.getRightLeafHeaders()
|
171
|
+
.slice(column.getPinnedIndex() + 1)
|
172
|
+
.reduce((acc, col) => acc + col.getSize(), 0);
|
173
|
+
};
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import {
|
2
|
+
type MRT_DefinedTableOptions,
|
3
|
+
type MRT_DisplayColumnIds,
|
4
|
+
type MRT_Localization,
|
5
|
+
type MRT_RowData,
|
6
|
+
type MRT_StatefulTableOptions,
|
7
|
+
} from '../types';
|
8
|
+
import { getAllLeafColumnDefs, getColumnId } from './column.utils';
|
9
|
+
|
10
|
+
export function defaultDisplayColumnProps<TData extends MRT_RowData>({
|
11
|
+
header,
|
12
|
+
id,
|
13
|
+
size = 60,
|
14
|
+
tableOptions,
|
15
|
+
}: {
|
16
|
+
header?: keyof MRT_Localization;
|
17
|
+
id: MRT_DisplayColumnIds;
|
18
|
+
size?: number;
|
19
|
+
tableOptions: MRT_DefinedTableOptions<TData>;
|
20
|
+
}) {
|
21
|
+
const { defaultDisplayColumn, displayColumnDefOptions, localization } =
|
22
|
+
tableOptions;
|
23
|
+
return {
|
24
|
+
...defaultDisplayColumn,
|
25
|
+
header: header ? localization[header]! : '',
|
26
|
+
size,
|
27
|
+
...displayColumnDefOptions?.[id],
|
28
|
+
id,
|
29
|
+
} as const;
|
30
|
+
}
|
31
|
+
|
32
|
+
export const showRowPinningColumn = <TData extends MRT_RowData>(
|
33
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
34
|
+
) => {
|
35
|
+
const { enableRowPinning, rowPinningDisplayMode } = tableOptions;
|
36
|
+
return enableRowPinning && !rowPinningDisplayMode?.startsWith('select');
|
37
|
+
};
|
38
|
+
|
39
|
+
export const showRowDragColumn = <TData extends MRT_RowData>(
|
40
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
41
|
+
) => {
|
42
|
+
const { enableRowDragging, enableRowOrdering } = tableOptions;
|
43
|
+
return enableRowDragging || enableRowOrdering;
|
44
|
+
};
|
45
|
+
|
46
|
+
export const showRowExpandColumn = <TData extends MRT_RowData>(
|
47
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
48
|
+
) => {
|
49
|
+
const {
|
50
|
+
enableExpanding,
|
51
|
+
enableGrouping,
|
52
|
+
renderDetailPanel,
|
53
|
+
state: { grouping },
|
54
|
+
} = tableOptions;
|
55
|
+
return !!(
|
56
|
+
enableExpanding ||
|
57
|
+
(enableGrouping && (grouping === undefined || grouping?.length)) ||
|
58
|
+
renderDetailPanel
|
59
|
+
);
|
60
|
+
};
|
61
|
+
|
62
|
+
export const showRowActionsColumn = <TData extends MRT_RowData>(
|
63
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
64
|
+
) => {
|
65
|
+
const {
|
66
|
+
createDisplayMode,
|
67
|
+
editDisplayMode,
|
68
|
+
enableEditing,
|
69
|
+
enableRowActions,
|
70
|
+
state: { creatingRow },
|
71
|
+
} = tableOptions;
|
72
|
+
return (
|
73
|
+
enableRowActions ||
|
74
|
+
(creatingRow && createDisplayMode === 'row') ||
|
75
|
+
(enableEditing && ['modal', 'row'].includes(editDisplayMode ?? ''))
|
76
|
+
);
|
77
|
+
};
|
78
|
+
|
79
|
+
export const showRowSelectionColumn = <TData extends MRT_RowData>(
|
80
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
81
|
+
) => tableOptions.enableRowSelection;
|
82
|
+
|
83
|
+
export const showRowNumbersColumn = <TData extends MRT_RowData>(
|
84
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
85
|
+
) => tableOptions.enableRowNumbers;
|
86
|
+
|
87
|
+
export const showRowSpacerColumn = <TData extends MRT_RowData>(
|
88
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
89
|
+
) => tableOptions.layoutMode === 'grid-no-grow';
|
90
|
+
|
91
|
+
export const getLeadingDisplayColumnIds = <TData extends MRT_RowData>(
|
92
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
93
|
+
) =>
|
94
|
+
[
|
95
|
+
showRowPinningColumn(tableOptions) && 'mrt-row-pin',
|
96
|
+
showRowDragColumn(tableOptions) && 'mrt-row-drag',
|
97
|
+
tableOptions.positionActionsColumn === 'first' &&
|
98
|
+
showRowActionsColumn(tableOptions) &&
|
99
|
+
'mrt-row-actions',
|
100
|
+
tableOptions.positionExpandColumn === 'first' &&
|
101
|
+
showRowExpandColumn(tableOptions) &&
|
102
|
+
'mrt-row-expand',
|
103
|
+
showRowSelectionColumn(tableOptions) && 'mrt-row-select',
|
104
|
+
showRowNumbersColumn(tableOptions) && 'mrt-row-numbers',
|
105
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
106
|
+
|
107
|
+
export const getTrailingDisplayColumnIds = <TData extends MRT_RowData>(
|
108
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
109
|
+
) =>
|
110
|
+
[
|
111
|
+
tableOptions.positionActionsColumn === 'last' &&
|
112
|
+
showRowActionsColumn(tableOptions) &&
|
113
|
+
'mrt-row-actions',
|
114
|
+
tableOptions.positionExpandColumn === 'last' &&
|
115
|
+
showRowExpandColumn(tableOptions) &&
|
116
|
+
'mrt-row-expand',
|
117
|
+
showRowSpacerColumn(tableOptions) && 'mrt-row-spacer',
|
118
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
119
|
+
|
120
|
+
export const getDefaultColumnOrderIds = <TData extends MRT_RowData>(
|
121
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
122
|
+
) => {
|
123
|
+
const leadingDisplayCols: string[] = getLeadingDisplayColumnIds(tableOptions);
|
124
|
+
const trailingDisplayCols: string[] =
|
125
|
+
getTrailingDisplayColumnIds(tableOptions);
|
126
|
+
const allLeafColumnDefs = getAllLeafColumnDefs(tableOptions.columns)
|
127
|
+
.map((columnDef) => getColumnId(columnDef))
|
128
|
+
.filter(
|
129
|
+
(columnId) =>
|
130
|
+
!leadingDisplayCols.includes(columnId) &&
|
131
|
+
!trailingDisplayCols.includes(columnId),
|
132
|
+
);
|
133
|
+
return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
|
134
|
+
};
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import { type MRT_RowData, type MRT_TableInstance } from '../types';
|
2
|
+
|
3
|
+
export const getCanRankRows = <TData extends MRT_RowData>(
|
4
|
+
table: MRT_TableInstance<TData>,
|
5
|
+
) => {
|
6
|
+
const { getState, options } = table;
|
7
|
+
const {
|
8
|
+
enableGlobalFilterRankedResults,
|
9
|
+
manualExpanding,
|
10
|
+
manualFiltering,
|
11
|
+
manualGrouping,
|
12
|
+
manualSorting,
|
13
|
+
} = options;
|
14
|
+
const { expanded, globalFilterFn } = getState();
|
15
|
+
|
16
|
+
return (
|
17
|
+
!manualExpanding &&
|
18
|
+
!manualFiltering &&
|
19
|
+
!manualGrouping &&
|
20
|
+
!manualSorting &&
|
21
|
+
enableGlobalFilterRankedResults &&
|
22
|
+
globalFilterFn === 'fuzzy' &&
|
23
|
+
expanded !== true &&
|
24
|
+
!Object.values(expanded).some(Boolean)
|
25
|
+
);
|
26
|
+
};
|