material-react-table 0.7.4 → 0.8.0-alpha.1
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 +25 -31
- package/dist/body/MRT_TableBody.d.ts +0 -1
- package/dist/body/MRT_TableBodyCell.d.ts +1 -0
- package/dist/body/MRT_TableBodyRow.d.ts +0 -1
- package/dist/buttons/MRT_ColumnPinningButtons.d.ts +8 -0
- package/dist/buttons/MRT_CopyButton.d.ts +2 -1
- package/dist/enums.d.ts +3 -3
- package/dist/filtersFNs.d.ts +31 -30
- package/dist/footer/MRT_TableFooter.d.ts +0 -1
- package/dist/head/MRT_TableHead.d.ts +0 -1
- package/dist/inputs/MRT_FilterRangeFields.d.ts +8 -0
- package/dist/inputs/MRT_FilterTextField.d.ts +1 -0
- package/dist/localization.d.ts +7 -2
- package/dist/material-react-table.cjs.development.js +489 -448
- 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 +492 -451
- package/dist/material-react-table.esm.js.map +1 -1
- package/dist/menus/{MRT_FilterTypeMenu.d.ts → MRT_FilterOptionMenu.d.ts} +1 -1
- package/dist/table/MRT_Table.d.ts +0 -1
- package/dist/toolbar/MRT_ToolbarTop.d.ts +1 -0
- package/dist/utils.d.ts +6 -6
- package/package.json +24 -24
- package/src/MaterialReactTable.tsx +39 -41
- package/src/body/MRT_TableBody.tsx +3 -11
- package/src/body/MRT_TableBodyCell.tsx +102 -51
- package/src/body/MRT_TableBodyRow.tsx +21 -30
- package/src/buttons/MRT_ColumnPinningButtons.tsx +57 -0
- package/src/buttons/MRT_CopyButton.tsx +3 -2
- package/src/buttons/MRT_EditActionButtons.tsx +1 -2
- package/src/buttons/MRT_ExpandAllButton.tsx +1 -2
- package/src/enums.ts +3 -3
- package/src/filtersFNs.ts +71 -81
- package/src/footer/MRT_TableFooter.tsx +6 -16
- package/src/footer/MRT_TableFooterCell.tsx +5 -7
- package/src/footer/MRT_TableFooterRow.tsx +5 -8
- package/src/head/MRT_TableHead.tsx +5 -16
- package/src/head/MRT_TableHeadCell.tsx +101 -44
- package/src/head/MRT_TableHeadRow.tsx +8 -15
- package/src/inputs/MRT_EditCellTextField.tsx +2 -2
- package/src/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/inputs/MRT_FilterTextField.tsx +84 -52
- package/src/inputs/MRT_SearchTextField.tsx +2 -2
- package/src/inputs/MRT_SelectCheckbox.tsx +16 -17
- package/src/localization.ts +15 -5
- package/src/menus/MRT_ColumnActionMenu.tsx +9 -8
- package/src/menus/{MRT_FilterTypeMenu.tsx → MRT_FilterOptionMenu.tsx} +54 -49
- package/src/menus/MRT_ShowHideColumnsMenu.tsx +25 -11
- package/src/menus/MRT_ShowHideColumnsMenuItems.tsx +15 -5
- package/src/table/MRT_Table.tsx +8 -19
- package/src/table/MRT_TableContainer.tsx +8 -69
- package/src/table/MRT_TableRoot.tsx +70 -70
- package/src/toolbar/MRT_LinearProgressBar.tsx +5 -2
- package/src/toolbar/MRT_ToolbarAlertBanner.tsx +3 -2
- package/src/toolbar/MRT_ToolbarTop.tsx +4 -6
- package/src/utils.ts +10 -10
package/dist/utils.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { ColumnDef, Table } from '@tanstack/react-table';
|
|
2
|
-
import { MRT_ColumnDef,
|
|
2
|
+
import { MRT_ColumnDef, MRT_FilterFn } from '.';
|
|
3
3
|
export declare const getAllLeafColumnDefs: (columns: MRT_ColumnDef[]) => MRT_ColumnDef[];
|
|
4
|
-
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>,
|
|
5
|
-
[key: string]:
|
|
4
|
+
export declare const createGroup: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
5
|
+
[key: string]: MRT_FilterFn<{}>;
|
|
6
6
|
}) => ColumnDef<D>;
|
|
7
|
-
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>,
|
|
8
|
-
[key: string]:
|
|
7
|
+
export declare const createDataColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: MRT_ColumnDef<D>, currentFilterFns: {
|
|
8
|
+
[key: string]: MRT_FilterFn<{}>;
|
|
9
9
|
}) => ColumnDef<D>;
|
|
10
|
-
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "
|
|
10
|
+
export declare const createDisplayColumn: <D extends Record<string, any> = {}>(table: Table<D>, column: Pick<MRT_ColumnDef<D>, "footer" | "columns" | "filterFn" | "id" | "accessorKey" | "accessorFn" | "cell" | "meta" | "enableHiding" | "enablePinning" | "enableColumnFilter" | "enableGlobalFilter" | "sortingFn" | "sortDescFirst" | "enableSorting" | "enableMultiSort" | "invertSorting" | "sortUndefined" | "aggregationFn" | "aggregatedCell" | "enableGrouping" | "enableResizing" | "size" | "minSize" | "maxSize" | "Edit" | "Filter" | "Footer" | "Header" | "Cell" | "enableClickToCopy" | "enableColumnActions" | "enableEditing" | "enabledColumnFilterOptions" | "filterSelectOptions" | "muiTableBodyCellCopyButtonProps" | "muiTableBodyCellEditTextFieldProps" | "muiTableBodyCellProps" | "muiTableFooterCellProps" | "muiTableHeadCellColumnActionsButtonProps" | "muiTableHeadCellFilterTextFieldProps" | "muiTableHeadCellProps" | "onCellEditBlur" | "onCellEditChange" | "onColumnFilterValueChange"> & {
|
|
11
11
|
header?: string | undefined;
|
|
12
12
|
}) => ColumnDef<D>;
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.
|
|
2
|
+
"version": "0.8.0-alpha.1",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"name": "material-react-table",
|
|
5
5
|
"description": "A fully featured Material UI implementation of react-table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
|
|
@@ -55,39 +55,39 @@
|
|
|
55
55
|
}
|
|
56
56
|
],
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@babel/core": "^7.
|
|
58
|
+
"@babel/core": "^7.18.2",
|
|
59
59
|
"@emotion/react": "^11.9.0",
|
|
60
60
|
"@emotion/styled": "^11.8.1",
|
|
61
61
|
"@etchteam/storybook-addon-status": "^4.2.1",
|
|
62
|
-
"@faker-js/faker": "^
|
|
63
|
-
"@mui/icons-material": "^5.
|
|
64
|
-
"@mui/material": "^5.
|
|
62
|
+
"@faker-js/faker": "^7.1.0",
|
|
63
|
+
"@mui/icons-material": "^5.8.0",
|
|
64
|
+
"@mui/material": "^5.8.1",
|
|
65
65
|
"@size-limit/preset-small-lib": "^7.0.8",
|
|
66
|
-
"@storybook/addon-a11y": "^6.
|
|
67
|
-
"@storybook/addon-actions": "^6.
|
|
66
|
+
"@storybook/addon-a11y": "^6.5.5",
|
|
67
|
+
"@storybook/addon-actions": "^6.5.5",
|
|
68
68
|
"@storybook/addon-console": "^1.2.3",
|
|
69
|
-
"@storybook/addon-essentials": "^6.
|
|
69
|
+
"@storybook/addon-essentials": "^6.5.5",
|
|
70
70
|
"@storybook/addon-info": "^5.3.21",
|
|
71
|
-
"@storybook/addon-links": "^6.
|
|
72
|
-
"@storybook/addon-storysource": "^6.
|
|
73
|
-
"@storybook/addons": "^6.
|
|
74
|
-
"@storybook/react": "^6.
|
|
75
|
-
"@types/react": "^
|
|
76
|
-
"@types/react-dom": "^
|
|
71
|
+
"@storybook/addon-links": "^6.5.5",
|
|
72
|
+
"@storybook/addon-storysource": "^6.5.5",
|
|
73
|
+
"@storybook/addons": "^6.5.5",
|
|
74
|
+
"@storybook/react": "^6.5.5",
|
|
75
|
+
"@types/react": "^18.0.9",
|
|
76
|
+
"@types/react-dom": "^18.0.5",
|
|
77
77
|
"babel-loader": "^8.2.5",
|
|
78
|
-
"eslint": "^8.
|
|
79
|
-
"eslint-plugin-react-hooks": "^4.
|
|
80
|
-
"husky": "^
|
|
78
|
+
"eslint": "^8.16.0",
|
|
79
|
+
"eslint-plugin-react-hooks": "^4.5.0",
|
|
80
|
+
"husky": "^8.0.1",
|
|
81
81
|
"prettier": "^2.6.2",
|
|
82
|
-
"react": "^
|
|
83
|
-
"react-dom": "^
|
|
84
|
-
"react-is": "^
|
|
82
|
+
"react": "^18.1.0",
|
|
83
|
+
"react-dom": "^18.1.0",
|
|
84
|
+
"react-is": "^18.1.0",
|
|
85
85
|
"size-limit": "^7.0.8",
|
|
86
86
|
"storybook-addon-paddings": "^4.3.0",
|
|
87
|
-
"storybook-dark-mode": "^1.0
|
|
87
|
+
"storybook-dark-mode": "^1.1.0",
|
|
88
88
|
"tsdx": "^0.14.1",
|
|
89
89
|
"tslib": "^2.4.0",
|
|
90
|
-
"typescript": "^4.
|
|
90
|
+
"typescript": "^4.7.2"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@emotion/react": ">=11",
|
|
@@ -97,7 +97,7 @@
|
|
|
97
97
|
"react": ">=16.8"
|
|
98
98
|
},
|
|
99
99
|
"dependencies": {
|
|
100
|
-
"@tanstack/
|
|
101
|
-
"
|
|
100
|
+
"@tanstack/match-sorter-utils": "^8.0.0-alpha.83",
|
|
101
|
+
"@tanstack/react-table": "^8.0.0-alpha.87"
|
|
102
102
|
}
|
|
103
103
|
}
|
|
@@ -30,34 +30,37 @@ import {
|
|
|
30
30
|
Cell,
|
|
31
31
|
Column,
|
|
32
32
|
ColumnDef,
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
FilterFn,
|
|
34
|
+
FilterFnOption,
|
|
35
35
|
Header,
|
|
36
36
|
HeaderGroup,
|
|
37
|
-
Options,
|
|
38
37
|
Overwrite,
|
|
39
38
|
PaginationState,
|
|
39
|
+
ReactTableGenerics,
|
|
40
40
|
Row,
|
|
41
|
+
TableGenerics,
|
|
41
42
|
TableInstance,
|
|
42
43
|
TableState,
|
|
44
|
+
UseTableInstanceOptions,
|
|
43
45
|
VisibilityState,
|
|
44
46
|
} from '@tanstack/react-table';
|
|
45
47
|
import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
|
|
46
48
|
import { MRT_Default_Icons, MRT_Icons } from './icons';
|
|
47
|
-
import {
|
|
49
|
+
import { MRT_FILTER_OPTION } from './enums';
|
|
48
50
|
import { MRT_TableRoot } from './table/MRT_TableRoot';
|
|
49
51
|
|
|
50
52
|
export type MRT_TableOptions<D extends Record<string, any> = {}> = Partial<
|
|
51
53
|
Omit<
|
|
52
|
-
|
|
53
|
-
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn'
|
|
54
|
+
UseTableInstanceOptions<ReactTableGenerics>,
|
|
55
|
+
'columns' | 'data' | 'initialState' | 'state' | 'expandRowsFn' | 'filterFns'
|
|
54
56
|
>
|
|
55
57
|
> & {
|
|
56
58
|
columns: MRT_ColumnDef<D>[];
|
|
57
59
|
data: D[];
|
|
60
|
+
expandRowsFn?: (dataRow: D) => D[];
|
|
61
|
+
filterFns?: MRT_FILTER_OPTION | FilterFn<D> | string | number | symbol;
|
|
58
62
|
initialState?: Partial<MRT_TableState<D>>;
|
|
59
63
|
state?: Partial<MRT_TableState<D>>;
|
|
60
|
-
expandRowsFn?: (dataRow: D) => D[];
|
|
61
64
|
};
|
|
62
65
|
|
|
63
66
|
export interface MRT_RowModel<D extends Record<string, any> = {}> {
|
|
@@ -69,7 +72,7 @@ export interface MRT_RowModel<D extends Record<string, any> = {}> {
|
|
|
69
72
|
export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
70
73
|
TableInstance<
|
|
71
74
|
Overwrite<
|
|
72
|
-
Partial<
|
|
75
|
+
Partial<TableGenerics>,
|
|
73
76
|
{
|
|
74
77
|
Row: D;
|
|
75
78
|
}
|
|
@@ -96,17 +99,16 @@ export type MRT_TableInstance<D extends Record<string, any> = {}> = Omit<
|
|
|
96
99
|
options: MaterialReactTableProps<D> & {
|
|
97
100
|
icons: MRT_Icons;
|
|
98
101
|
idPrefix: string;
|
|
99
|
-
filterTypes: { [key in MRT_FILTER_TYPE]: any };
|
|
100
102
|
localization: MRT_Localization;
|
|
101
103
|
};
|
|
102
|
-
setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell
|
|
103
|
-
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row
|
|
104
|
-
|
|
104
|
+
setCurrentEditingCell: Dispatch<SetStateAction<MRT_Cell | null>>;
|
|
105
|
+
setCurrentEditingRow: Dispatch<SetStateAction<MRT_Row | null>>;
|
|
106
|
+
setCurrentFilterFns: Dispatch<
|
|
105
107
|
SetStateAction<{
|
|
106
|
-
[key: string]:
|
|
108
|
+
[key: string]: MRT_FilterFn;
|
|
107
109
|
}>
|
|
108
110
|
>;
|
|
109
|
-
|
|
111
|
+
setCurrentGlobalFilterFn: Dispatch<SetStateAction<MRT_FilterFn<D>>>;
|
|
110
112
|
setIsDensePadding: Dispatch<SetStateAction<boolean>>;
|
|
111
113
|
setIsFullScreen: Dispatch<SetStateAction<boolean>>;
|
|
112
114
|
setShowFilters: Dispatch<SetStateAction<boolean>>;
|
|
@@ -119,34 +121,33 @@ export type MRT_TableState<D extends Record<string, any> = {}> = Omit<
|
|
|
119
121
|
> & {
|
|
120
122
|
currentEditingCell: MRT_Cell<D> | null;
|
|
121
123
|
currentEditingRow: MRT_Row<D> | null;
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
currentFilterFns: Record<string, string | Function>;
|
|
125
|
+
currentGlobalFilterFn: Record<string, string | Function>;
|
|
124
126
|
isDensePadding: boolean;
|
|
127
|
+
isLoading: boolean;
|
|
125
128
|
isFullScreen: boolean;
|
|
129
|
+
pagination: Partial<PaginationState>;
|
|
126
130
|
showFilters: boolean;
|
|
127
131
|
showGlobalFilter: boolean;
|
|
128
|
-
|
|
132
|
+
showProgressBars: boolean;
|
|
133
|
+
showSkeletons: boolean;
|
|
129
134
|
};
|
|
130
135
|
|
|
131
136
|
export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
132
137
|
ColumnDef<D>,
|
|
133
|
-
'header' | 'footer' | 'columns'
|
|
138
|
+
'header' | 'footer' | 'columns' | 'filterFn'
|
|
134
139
|
> & {
|
|
135
140
|
Edit?: ({
|
|
136
141
|
cell,
|
|
137
142
|
tableInstance,
|
|
138
|
-
}:
|
|
139
|
-
{
|
|
143
|
+
}: {
|
|
140
144
|
cell: MRT_Cell<D>;
|
|
141
145
|
tableInstance: MRT_TableInstance<D>;
|
|
142
|
-
// onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
143
146
|
}) => ReactNode;
|
|
144
147
|
Filter?: ({
|
|
145
|
-
// onChange,
|
|
146
148
|
header,
|
|
147
149
|
tableInstance,
|
|
148
150
|
}: {
|
|
149
|
-
// onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
150
151
|
header: MRT_Header<D>;
|
|
151
152
|
tableInstance: MRT_TableInstance<D>;
|
|
152
153
|
}) => ReactNode;
|
|
@@ -176,8 +177,8 @@ export type MRT_ColumnDef<D extends Record<string, any> = {}> = Omit<
|
|
|
176
177
|
enableClickToCopy?: boolean;
|
|
177
178
|
enableColumnActions?: boolean;
|
|
178
179
|
enableEditing?: boolean;
|
|
179
|
-
|
|
180
|
-
|
|
180
|
+
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
181
|
+
filterFn?: MRT_FilterFn;
|
|
181
182
|
filterSelectOptions?: (string | { text: string; value: string })[];
|
|
182
183
|
footer?: string;
|
|
183
184
|
header: string;
|
|
@@ -297,18 +298,9 @@ export type MRT_HeaderGroup<D extends Record<string, any> = {}> = Omit<
|
|
|
297
298
|
|
|
298
299
|
export type MRT_Row<D extends Record<string, any> = {}> = Omit<
|
|
299
300
|
Row<D>,
|
|
300
|
-
| '
|
|
301
|
-
| 'getAllCells'
|
|
302
|
-
| 'subRows'
|
|
303
|
-
| 'original'
|
|
304
|
-
| 'getLeftVisibleCells'
|
|
305
|
-
| 'getRightVisibleCells'
|
|
306
|
-
| 'getCenterVisibleCells'
|
|
301
|
+
'getVisibleCells' | 'getAllCells' | 'subRows' | 'original'
|
|
307
302
|
> & {
|
|
308
303
|
getAllCells: () => MRT_Cell<D>[];
|
|
309
|
-
getCenterVisibleCells: () => MRT_Cell<D>[];
|
|
310
|
-
getLeftVisibleCells: () => MRT_Cell<D>[];
|
|
311
|
-
getRightVisibleCells: () => MRT_Cell<D>[];
|
|
312
304
|
getVisibleCells: () => MRT_Cell<D>[];
|
|
313
305
|
subRows?: MRT_Row<D>[];
|
|
314
306
|
original: D;
|
|
@@ -322,7 +314,13 @@ export type MRT_Cell<D extends Record<string, any> = {}> = Omit<
|
|
|
322
314
|
row: MRT_Row<D>;
|
|
323
315
|
};
|
|
324
316
|
|
|
325
|
-
export type
|
|
317
|
+
export type MRT_FilterFn<D extends Record<string, any> = {}> =
|
|
318
|
+
| FilterFn<TableGenerics>
|
|
319
|
+
| FilterFnOption<D>
|
|
320
|
+
| MRT_FILTER_OPTION
|
|
321
|
+
| number
|
|
322
|
+
| string
|
|
323
|
+
| symbol;
|
|
326
324
|
|
|
327
325
|
export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
328
326
|
MRT_TableOptions<D> & {
|
|
@@ -344,12 +342,10 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
|
|
|
344
342
|
enableToolbarBottom?: boolean;
|
|
345
343
|
enableToolbarInternalActions?: boolean;
|
|
346
344
|
enableToolbarTop?: boolean;
|
|
347
|
-
|
|
348
|
-
|
|
345
|
+
enabledColumnFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
346
|
+
enabledGlobalFilterOptions?: (MRT_FILTER_OPTION | string)[];
|
|
349
347
|
icons?: Partial<MRT_Icons>;
|
|
350
348
|
idPrefix?: string;
|
|
351
|
-
isLoading?: boolean;
|
|
352
|
-
isReloading?: boolean;
|
|
353
349
|
localization?: Partial<MRT_Localization>;
|
|
354
350
|
muiLinearProgressProps?:
|
|
355
351
|
| LinearProgressProps
|
|
@@ -770,6 +766,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
770
766
|
enableHiding = true,
|
|
771
767
|
enableMultiRowSelection = true,
|
|
772
768
|
enablePagination = true,
|
|
769
|
+
enablePinning = false,
|
|
773
770
|
enableSelectAll = true,
|
|
774
771
|
enableSorting = true,
|
|
775
772
|
enableStickyHeader = true,
|
|
@@ -792,8 +789,8 @@ export default <D extends Record<string, any> = {}>({
|
|
|
792
789
|
columnResizeMode={columnResizeMode}
|
|
793
790
|
editingMode={editingMode}
|
|
794
791
|
enableColumnActions={enableColumnActions}
|
|
795
|
-
enableColumnResizing={enableColumnResizing}
|
|
796
792
|
enableColumnFilters={enableColumnFilters}
|
|
793
|
+
enableColumnResizing={enableColumnResizing}
|
|
797
794
|
enableDensePaddingToggle={enableDensePaddingToggle}
|
|
798
795
|
enableExpandAll={enableExpandAll}
|
|
799
796
|
enableFilters={enableFilters}
|
|
@@ -802,6 +799,7 @@ export default <D extends Record<string, any> = {}>({
|
|
|
802
799
|
enableHiding={enableHiding}
|
|
803
800
|
enableMultiRowSelection={enableMultiRowSelection}
|
|
804
801
|
enablePagination={enablePagination}
|
|
802
|
+
enablePinning={enablePinning}
|
|
805
803
|
enableSelectAll={enableSelectAll}
|
|
806
804
|
enableSorting={enableSorting}
|
|
807
805
|
enableStickyHeader={enableStickyHeader}
|
|
@@ -4,15 +4,13 @@ import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
|
4
4
|
import { MRT_TableInstance } from '..';
|
|
5
5
|
|
|
6
6
|
interface Props {
|
|
7
|
-
pinned: 'left' | 'center' | 'right' | 'none';
|
|
8
7
|
tableInstance: MRT_TableInstance;
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
export const MRT_TableBody: FC<Props> = ({
|
|
10
|
+
export const MRT_TableBody: FC<Props> = ({ tableInstance }) => {
|
|
12
11
|
const {
|
|
13
12
|
getPaginationRowModel,
|
|
14
13
|
getPrePaginationRowModel,
|
|
15
|
-
getTableBodyProps,
|
|
16
14
|
options: { enablePagination, muiTableBodyProps },
|
|
17
15
|
} = tableInstance;
|
|
18
16
|
|
|
@@ -20,22 +18,16 @@ export const MRT_TableBody: FC<Props> = ({ pinned, tableInstance }) => {
|
|
|
20
18
|
? getPaginationRowModel().rows
|
|
21
19
|
: getPrePaginationRowModel().rows;
|
|
22
20
|
|
|
23
|
-
const
|
|
21
|
+
const tableBodyProps =
|
|
24
22
|
muiTableBodyProps instanceof Function
|
|
25
23
|
? muiTableBodyProps({ tableInstance })
|
|
26
24
|
: muiTableBodyProps;
|
|
27
25
|
|
|
28
|
-
const tableBodyProps = {
|
|
29
|
-
...getTableBodyProps(),
|
|
30
|
-
...mTableBodyProps,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
26
|
return (
|
|
34
27
|
<TableBody {...tableBodyProps}>
|
|
35
28
|
{rows.map((row) => (
|
|
36
29
|
<MRT_TableBodyRow
|
|
37
|
-
key={row.
|
|
38
|
-
pinned={pinned}
|
|
30
|
+
key={row.id}
|
|
39
31
|
row={row}
|
|
40
32
|
tableInstance={tableInstance}
|
|
41
33
|
/>
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
import React, { FC, MouseEvent, useMemo } from 'react';
|
|
2
|
-
import { Skeleton, TableCell } from '@mui/material';
|
|
2
|
+
import { alpha, darken, lighten, Skeleton, TableCell } from '@mui/material';
|
|
3
3
|
import { MRT_EditCellTextField } from '../inputs/MRT_EditCellTextField';
|
|
4
4
|
import type { MRT_Cell, MRT_TableInstance } from '..';
|
|
5
5
|
import { MRT_CopyButton } from '../buttons/MRT_CopyButton';
|
|
6
6
|
|
|
7
7
|
interface Props {
|
|
8
8
|
cell: MRT_Cell;
|
|
9
|
+
enableHover?: boolean;
|
|
9
10
|
tableInstance: MRT_TableInstance;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export const MRT_TableBodyCell: FC<Props> = ({
|
|
13
|
+
export const MRT_TableBodyCell: FC<Props> = ({
|
|
14
|
+
cell,
|
|
15
|
+
enableHover,
|
|
16
|
+
tableInstance,
|
|
17
|
+
}) => {
|
|
13
18
|
const {
|
|
14
|
-
getIsSomeColumnsPinned,
|
|
15
19
|
getState,
|
|
16
20
|
options: {
|
|
17
21
|
editingMode,
|
|
18
22
|
enableClickToCopy,
|
|
19
23
|
enableEditing,
|
|
20
|
-
enablePinning,
|
|
21
24
|
idPrefix,
|
|
22
|
-
isLoading,
|
|
23
25
|
muiTableBodyCellProps,
|
|
24
26
|
muiTableBodyCellSkeletonProps,
|
|
25
27
|
onCellClick,
|
|
@@ -27,7 +29,13 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
27
29
|
setCurrentEditingCell,
|
|
28
30
|
} = tableInstance;
|
|
29
31
|
|
|
30
|
-
const {
|
|
32
|
+
const {
|
|
33
|
+
currentEditingCell,
|
|
34
|
+
currentEditingRow,
|
|
35
|
+
isDensePadding,
|
|
36
|
+
isLoading,
|
|
37
|
+
showSkeletons,
|
|
38
|
+
} = getState();
|
|
31
39
|
|
|
32
40
|
const { column, row } = cell;
|
|
33
41
|
|
|
@@ -42,7 +50,6 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
42
50
|
: column.muiTableBodyCellProps;
|
|
43
51
|
|
|
44
52
|
const tableCellProps = {
|
|
45
|
-
...cell.getCellProps(),
|
|
46
53
|
...mTableCellBodyProps,
|
|
47
54
|
...mcTableCellBodyProps,
|
|
48
55
|
};
|
|
@@ -50,10 +57,10 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
50
57
|
const skeletonWidth = useMemo(
|
|
51
58
|
() =>
|
|
52
59
|
column.columnDefType === 'display'
|
|
53
|
-
? column.
|
|
54
|
-
: Math.random() * (column.
|
|
55
|
-
column.
|
|
56
|
-
[column.columnDefType, column.
|
|
60
|
+
? column.getSize() / 2
|
|
61
|
+
: Math.random() * (column.getSize() - column.getSize() / 3) +
|
|
62
|
+
column.getSize() / 3,
|
|
63
|
+
[column.columnDefType, column.getSize()],
|
|
57
64
|
);
|
|
58
65
|
|
|
59
66
|
const isEditable =
|
|
@@ -84,6 +91,26 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
84
91
|
}
|
|
85
92
|
};
|
|
86
93
|
|
|
94
|
+
const getIsLastLeftPinnedColumn = () => {
|
|
95
|
+
return (
|
|
96
|
+
column.getIsPinned() === 'left' &&
|
|
97
|
+
tableInstance.getLeftLeafHeaders().length - 1 === column.getPinnedIndex()
|
|
98
|
+
);
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const getIsFirstRightPinnedColumn = () => {
|
|
102
|
+
return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const getTotalRight = () => {
|
|
106
|
+
return (
|
|
107
|
+
(tableInstance.getRightLeafHeaders().length -
|
|
108
|
+
1 -
|
|
109
|
+
column.getPinnedIndex()) *
|
|
110
|
+
150
|
|
111
|
+
);
|
|
112
|
+
};
|
|
113
|
+
|
|
87
114
|
return (
|
|
88
115
|
<TableCell
|
|
89
116
|
onClick={(event: MouseEvent<HTMLTableCellElement>) =>
|
|
@@ -91,10 +118,22 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
91
118
|
}
|
|
92
119
|
onDoubleClick={handleDoubleClick}
|
|
93
120
|
{...tableCellProps}
|
|
94
|
-
sx={{
|
|
121
|
+
sx={(theme) => ({
|
|
122
|
+
backgroundColor: column.getIsPinned()
|
|
123
|
+
? alpha(lighten(theme.palette.background.default, 0.04), 0.95)
|
|
124
|
+
: undefined,
|
|
125
|
+
boxShadow: getIsLastLeftPinnedColumn()
|
|
126
|
+
? `4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
127
|
+
: getIsFirstRightPinnedColumn()
|
|
128
|
+
? `-4px 0 4px -2px ${alpha(theme.palette.common.black, 0.1)}`
|
|
129
|
+
: undefined,
|
|
95
130
|
cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'text',
|
|
96
|
-
|
|
97
|
-
|
|
131
|
+
left:
|
|
132
|
+
column.getIsPinned() === 'left'
|
|
133
|
+
? `${column.getStart('left')}px`
|
|
134
|
+
: undefined,
|
|
135
|
+
maxWidth: `min(${column.getSize()}px, fit-content)`,
|
|
136
|
+
minWidth: `max${column.getSize()}px, ${column.minSize}px`,
|
|
98
137
|
p: isDensePadding
|
|
99
138
|
? column.columnDefType === 'display'
|
|
100
139
|
? '0 0.5rem'
|
|
@@ -106,46 +145,58 @@ export const MRT_TableBodyCell: FC<Props> = ({ cell, tableInstance }) => {
|
|
|
106
145
|
column.id === 'mrt-expand'
|
|
107
146
|
? `${row.depth + (isDensePadding ? 0.5 : 0.75)}rem`
|
|
108
147
|
: undefined,
|
|
148
|
+
position: column.getIsPinned() ? 'sticky' : 'relative',
|
|
149
|
+
right:
|
|
150
|
+
column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
|
|
109
151
|
transition: 'all 0.2s ease-in-out',
|
|
110
|
-
whiteSpace:
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
152
|
+
whiteSpace: isDensePadding ? 'nowrap' : 'normal',
|
|
153
|
+
width: column.getSize(),
|
|
154
|
+
zIndex: column.getIsPinned() ? 1 : undefined,
|
|
155
|
+
'&:hover': {
|
|
156
|
+
backgroundColor: enableHover
|
|
157
|
+
? theme.palette.mode === 'dark'
|
|
158
|
+
? `${lighten(theme.palette.background.default, 0.13)} !important`
|
|
159
|
+
: `${darken(theme.palette.background.default, 0.07)} !important`
|
|
160
|
+
: undefined,
|
|
161
|
+
},
|
|
162
|
+
...(tableCellProps?.sx as any),
|
|
163
|
+
})}
|
|
118
164
|
>
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
column.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
column.enableClickToCopy
|
|
137
|
-
|
|
138
|
-
|
|
165
|
+
<>
|
|
166
|
+
{isLoading || showSkeletons ? (
|
|
167
|
+
<Skeleton
|
|
168
|
+
animation="wave"
|
|
169
|
+
height={20}
|
|
170
|
+
width={skeletonWidth}
|
|
171
|
+
{...muiTableBodyCellSkeletonProps}
|
|
172
|
+
/>
|
|
173
|
+
) : column.columnDefType === 'display' ? (
|
|
174
|
+
column.Cell?.({ cell, tableInstance })
|
|
175
|
+
) : cell.getIsPlaceholder() ||
|
|
176
|
+
(row.getIsGrouped() &&
|
|
177
|
+
column.id !==
|
|
178
|
+
row.groupingColumnId) ? null : cell.getIsAggregated() ? (
|
|
179
|
+
cell.renderAggregatedCell()
|
|
180
|
+
) : isEditing ? (
|
|
181
|
+
<MRT_EditCellTextField cell={cell} tableInstance={tableInstance} />
|
|
182
|
+
) : (enableClickToCopy || column.enableClickToCopy) &&
|
|
183
|
+
column.enableClickToCopy !== false ? (
|
|
184
|
+
<>
|
|
185
|
+
<MRT_CopyButton cell={cell} tableInstance={tableInstance}>
|
|
186
|
+
<>
|
|
187
|
+
{cell.column?.Cell?.({ cell, tableInstance }) ??
|
|
188
|
+
cell.renderCell()}
|
|
189
|
+
</>
|
|
190
|
+
</MRT_CopyButton>
|
|
191
|
+
{row.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
192
|
+
</>
|
|
193
|
+
) : (
|
|
194
|
+
<>
|
|
139
195
|
{cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
<>
|
|
145
|
-
{cell.column?.Cell?.({ cell, tableInstance }) ?? cell.renderCell()}
|
|
146
|
-
{row.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
147
|
-
</>
|
|
148
|
-
)}
|
|
196
|
+
{row.getIsGrouped() && <> ({row.subRows?.length})</>}
|
|
197
|
+
</>
|
|
198
|
+
)}
|
|
199
|
+
</>
|
|
149
200
|
</TableCell>
|
|
150
201
|
);
|
|
151
202
|
};
|