material-react-table 1.0.11 → 1.1.0-beta.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/cjs/MaterialReactTable.d.ts +10 -3
- package/dist/cjs/body/MRT_TableBody.d.ts +2 -1
- package/dist/cjs/body/MRT_TableBodyCell.d.ts +2 -1
- package/dist/cjs/body/MRT_TableBodyRow.d.ts +2 -1
- package/dist/cjs/index.js +75 -46
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/table/MRT_TableRoot.d.ts +3 -2
- package/dist/esm/MaterialReactTable.d.ts +10 -3
- package/dist/esm/body/MRT_TableBody.d.ts +2 -1
- package/dist/esm/body/MRT_TableBodyCell.d.ts +2 -1
- package/dist/esm/body/MRT_TableBodyRow.d.ts +2 -1
- package/dist/esm/material-react-table.esm.js +77 -48
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/table/MRT_TableRoot.d.ts +3 -2
- package/dist/index.d.ts +10 -3
- package/package.json +1 -1
- package/src/MaterialReactTable.tsx +11 -3
- package/src/body/MRT_TableBody.tsx +18 -12
- package/src/body/MRT_TableBodyCell.tsx +7 -1
- package/src/body/MRT_TableBodyRow.tsx +36 -15
- package/src/body/MRT_TableDetailPanel.tsx +1 -1
- package/src/buttons/MRT_ExpandAllButton.tsx +1 -1
- package/src/buttons/MRT_ExpandButton.tsx +1 -1
- package/src/buttons/MRT_GrabHandleButton.tsx +1 -1
- package/src/buttons/MRT_ToggleRowActionMenuButton.tsx +1 -1
- package/src/column.utils.ts +1 -1
- package/src/head/MRT_TableHeadCellColumnActionsButton.tsx +9 -7
- package/src/head/MRT_TableHeadCellResizeHandle.tsx +3 -1
- package/src/inputs/MRT_SelectCheckbox.tsx +51 -46
- package/src/table/MRT_Table.tsx +7 -2
- package/src/table/MRT_TablePaper.tsx +1 -1
- package/src/table/MRT_TableRoot.tsx +1 -1
- package/src/toolbar/MRT_TopToolbar.tsx +1 -1
|
@@ -45,6 +45,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
45
45
|
icons?: Partial<import("..").MRT_Icons> | undefined;
|
|
46
46
|
initialState?: Partial<MRT_TableState<TData>> | undefined;
|
|
47
47
|
localization?: Partial<MRT_Localization> | undefined;
|
|
48
|
+
memoMode?: "cell" | "row" | "table-body" | undefined;
|
|
48
49
|
muiBottomToolbarProps?: import("@mui/material").ToolbarProps<"div", {}> | (({ table }: {
|
|
49
50
|
table: MRT_TableInstance<TData>;
|
|
50
51
|
}) => import("@mui/material").ToolbarProps<"div", {}>) | undefined;
|
|
@@ -65,10 +66,10 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
|
|
|
65
66
|
muiSelectAllCheckboxProps?: import("@mui/material").CheckboxProps | (({ table }: {
|
|
66
67
|
table: MRT_TableInstance<TData>;
|
|
67
68
|
}) => import("@mui/material").CheckboxProps) | undefined;
|
|
68
|
-
muiSelectCheckboxProps?: import("@mui/material").CheckboxProps | (({ table, row, }: {
|
|
69
|
+
muiSelectCheckboxProps?: import("@mui/material").CheckboxProps | import("@mui/material").RadioProps | (({ table, row, }: {
|
|
69
70
|
table: MRT_TableInstance<TData>;
|
|
70
71
|
row: MRT_Row<TData>;
|
|
71
|
-
}) => import("@mui/material").CheckboxProps) | undefined;
|
|
72
|
+
}) => import("@mui/material").CheckboxProps | import("@mui/material").RadioProps) | undefined;
|
|
72
73
|
muiTableBodyCellCopyButtonProps?: import("@mui/material").ButtonProps<"button", {}> | (({ cell, column, row, table, }: {
|
|
73
74
|
cell: MRT_Cell<TData>;
|
|
74
75
|
column: MRT_Column<TData>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MutableRefObject, Dispatch, SetStateAction, ReactNode } from 'react';
|
|
2
|
-
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, CheckboxProps, ToolbarProps, LinearProgressProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
|
|
2
|
+
import { ButtonProps, TextFieldProps, TableCellProps, IconButtonProps, CheckboxProps, ToolbarProps, LinearProgressProps, RadioProps, SkeletonProps, TableBodyProps, TableRowProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, PaperProps, TableProps, ChipProps, AlertProps } from '@mui/material';
|
|
3
3
|
import { Row, Table, TableState, ColumnDef, DeepKeys, Column, Header, HeaderGroup, Cell, SortingFn, FilterFn, TableOptions, OnChangeFn } from '@tanstack/react-table';
|
|
4
4
|
import { Options, VirtualItem } from 'react-virtual';
|
|
5
5
|
import * as _tanstack_table_core from '@tanstack/table-core';
|
|
@@ -558,6 +558,13 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
558
558
|
* @link https://www.material-react-table.com/docs/guides/localization
|
|
559
559
|
*/
|
|
560
560
|
localization?: Partial<MRT_Localization>;
|
|
561
|
+
/**
|
|
562
|
+
* Memoize cells, rows, or the entire table body to potentially improve render performance.
|
|
563
|
+
*
|
|
564
|
+
* @warning This will break some dynamic rendering features. See the memoization guide for more info:
|
|
565
|
+
* @link https://www.material-react-table.com/docs/guides/memoize-components
|
|
566
|
+
*/
|
|
567
|
+
memoMode?: 'cell' | 'row' | 'table-body';
|
|
561
568
|
muiBottomToolbarProps?: ToolbarProps | (({ table }: {
|
|
562
569
|
table: MRT_TableInstance<TData>;
|
|
563
570
|
}) => ToolbarProps);
|
|
@@ -578,10 +585,10 @@ declare type MaterialReactTableProps<TData extends Record<string, any> = {}> = O
|
|
|
578
585
|
muiSelectAllCheckboxProps?: CheckboxProps | (({ table }: {
|
|
579
586
|
table: MRT_TableInstance<TData>;
|
|
580
587
|
}) => CheckboxProps);
|
|
581
|
-
muiSelectCheckboxProps?: CheckboxProps | (({ table, row, }: {
|
|
588
|
+
muiSelectCheckboxProps?: (CheckboxProps | RadioProps) | (({ table, row, }: {
|
|
582
589
|
table: MRT_TableInstance<TData>;
|
|
583
590
|
row: MRT_Row<TData>;
|
|
584
|
-
}) => CheckboxProps);
|
|
591
|
+
}) => CheckboxProps | RadioProps);
|
|
585
592
|
muiTableBodyCellCopyButtonProps?: ButtonProps | (({ cell, column, row, table, }: {
|
|
586
593
|
cell: MRT_Cell<TData>;
|
|
587
594
|
column: MRT_Column<TData>;
|
package/package.json
CHANGED
|
@@ -13,6 +13,7 @@ import type {
|
|
|
13
13
|
IconButtonProps,
|
|
14
14
|
LinearProgressProps,
|
|
15
15
|
PaperProps,
|
|
16
|
+
RadioProps,
|
|
16
17
|
SkeletonProps,
|
|
17
18
|
TableBodyProps,
|
|
18
19
|
TableCellProps,
|
|
@@ -668,11 +669,18 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
668
669
|
initialState?: Partial<MRT_TableState<TData>>;
|
|
669
670
|
/**
|
|
670
671
|
* Pass in either a locale imported from `material-react-table/locales/*` or a custom locale object.
|
|
671
|
-
*
|
|
672
|
+
*
|
|
672
673
|
* See the localization (i18n) guide for more info:
|
|
673
674
|
* @link https://www.material-react-table.com/docs/guides/localization
|
|
674
675
|
*/
|
|
675
676
|
localization?: Partial<MRT_Localization>;
|
|
677
|
+
/**
|
|
678
|
+
* Memoize cells, rows, or the entire table body to potentially improve render performance.
|
|
679
|
+
*
|
|
680
|
+
* @warning This will break some dynamic rendering features. See the memoization guide for more info:
|
|
681
|
+
* @link https://www.material-react-table.com/docs/guides/memoize-components
|
|
682
|
+
*/
|
|
683
|
+
memoMode?: 'cell' | 'row' | 'table-body';
|
|
676
684
|
muiBottomToolbarProps?:
|
|
677
685
|
| ToolbarProps
|
|
678
686
|
| (({ table }: { table: MRT_TableInstance<TData> }) => ToolbarProps);
|
|
@@ -704,14 +712,14 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
|
704
712
|
| CheckboxProps
|
|
705
713
|
| (({ table }: { table: MRT_TableInstance<TData> }) => CheckboxProps);
|
|
706
714
|
muiSelectCheckboxProps?:
|
|
707
|
-
| CheckboxProps
|
|
715
|
+
| (CheckboxProps | RadioProps)
|
|
708
716
|
| (({
|
|
709
717
|
table,
|
|
710
718
|
row,
|
|
711
719
|
}: {
|
|
712
720
|
table: MRT_TableInstance<TData>;
|
|
713
721
|
row: MRT_Row<TData>;
|
|
714
|
-
}) => CheckboxProps);
|
|
722
|
+
}) => CheckboxProps | RadioProps);
|
|
715
723
|
muiTableBodyCellCopyButtonProps?:
|
|
716
724
|
| ButtonProps
|
|
717
725
|
| (({
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import React, { FC, useMemo } from 'react';
|
|
1
|
+
import React, { FC, memo, useMemo } from 'react';
|
|
2
2
|
import { useVirtual } from 'react-virtual'; //stuck on v2 for now
|
|
3
3
|
// import { useVirtualizer, Virtualizer } from '@tanstack/react-virtual';
|
|
4
4
|
import { TableBody, Typography } from '@mui/material';
|
|
5
|
-
import { MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
5
|
+
import { Memo_MRT_TableBodyRow, MRT_TableBodyRow } from './MRT_TableBodyRow';
|
|
6
6
|
import { rankGlobalFuzzy } from '../sortingFns';
|
|
7
7
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
8
8
|
|
|
@@ -22,6 +22,7 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
|
|
|
22
22
|
localization,
|
|
23
23
|
manualFiltering,
|
|
24
24
|
manualSorting,
|
|
25
|
+
memoMode,
|
|
25
26
|
muiTableBodyProps,
|
|
26
27
|
virtualizerInstanceRef,
|
|
27
28
|
virtualizerProps,
|
|
@@ -148,16 +149,19 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
|
|
|
148
149
|
const row = enableRowVirtualization
|
|
149
150
|
? (rows[rowOrVirtualRow.index] as MRT_Row)
|
|
150
151
|
: (rowOrVirtualRow as MRT_Row);
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
152
|
+
const props = {
|
|
153
|
+
key: row.id,
|
|
154
|
+
row,
|
|
155
|
+
rowIndex: enableRowVirtualization
|
|
156
|
+
? rowOrVirtualRow.index
|
|
157
|
+
: rowIndex,
|
|
158
|
+
table,
|
|
159
|
+
virtualRow: enableRowVirtualization ? rowOrVirtualRow : null,
|
|
160
|
+
};
|
|
161
|
+
return memoMode === 'row' ? (
|
|
162
|
+
<Memo_MRT_TableBodyRow {...props} />
|
|
163
|
+
) : (
|
|
164
|
+
<MRT_TableBodyRow {...props} />
|
|
161
165
|
);
|
|
162
166
|
},
|
|
163
167
|
)}
|
|
@@ -171,3 +175,5 @@ export const MRT_TableBody: FC<Props> = ({ table }) => {
|
|
|
171
175
|
</TableBody>
|
|
172
176
|
);
|
|
173
177
|
};
|
|
178
|
+
|
|
179
|
+
export const Memo_MRT_TableBody = memo(MRT_TableBody, () => true);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
DragEvent,
|
|
3
3
|
FC,
|
|
4
|
+
memo,
|
|
4
5
|
MouseEvent,
|
|
5
6
|
RefObject,
|
|
6
7
|
useEffect,
|
|
@@ -167,7 +168,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
167
168
|
onDragEnter={handleDragEnter}
|
|
168
169
|
onDoubleClick={handleDoubleClick}
|
|
169
170
|
sx={(theme) => ({
|
|
170
|
-
cursor: isEditable && editingMode === 'cell' ? 'pointer' : '
|
|
171
|
+
cursor: isEditable && editingMode === 'cell' ? 'pointer' : 'inherit',
|
|
171
172
|
overflow: 'hidden',
|
|
172
173
|
p:
|
|
173
174
|
density === 'compact'
|
|
@@ -251,3 +252,8 @@ export const MRT_TableBodyCell: FC<Props> = ({
|
|
|
251
252
|
</TableCell>
|
|
252
253
|
);
|
|
253
254
|
};
|
|
255
|
+
|
|
256
|
+
export const Memo_MRT_TableBodyCell = memo(
|
|
257
|
+
MRT_TableBodyCell,
|
|
258
|
+
(prev, next) => next.cell === prev.cell,
|
|
259
|
+
);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import React, { DragEvent, FC, useRef } from 'react';
|
|
1
|
+
import React, { DragEvent, FC, memo, useRef } from 'react';
|
|
2
2
|
import { darken, lighten, TableRow, useTheme } from '@mui/material';
|
|
3
|
-
import { MRT_TableBodyCell } from './MRT_TableBodyCell';
|
|
3
|
+
import { Memo_MRT_TableBodyCell, MRT_TableBodyCell } from './MRT_TableBodyCell';
|
|
4
4
|
import { MRT_TableDetailPanel } from './MRT_TableDetailPanel';
|
|
5
5
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
6
6
|
|
|
@@ -21,10 +21,16 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
|
21
21
|
const {
|
|
22
22
|
getIsSomeColumnsPinned,
|
|
23
23
|
getState,
|
|
24
|
-
options: {
|
|
24
|
+
options: {
|
|
25
|
+
enableRowOrdering,
|
|
26
|
+
memoMode,
|
|
27
|
+
muiTableBodyRowProps,
|
|
28
|
+
renderDetailPanel,
|
|
29
|
+
},
|
|
25
30
|
setHoveredRow,
|
|
26
31
|
} = table;
|
|
27
|
-
const { draggingRow, hoveredRow } =
|
|
32
|
+
const { draggingColumn, draggingRow, editingCell, editingRow, hoveredRow } =
|
|
33
|
+
getState();
|
|
28
34
|
|
|
29
35
|
const tableRowProps =
|
|
30
36
|
muiTableBodyRowProps instanceof Function
|
|
@@ -69,7 +75,7 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
|
69
75
|
backgroundColor: lighten(theme.palette.background.default, 0.06),
|
|
70
76
|
opacity:
|
|
71
77
|
draggingRow?.id === row.id || hoveredRow?.id === row.id ? 0.5 : 1,
|
|
72
|
-
transition: 'all
|
|
78
|
+
transition: 'all 150ms ease-in-out',
|
|
73
79
|
'&:hover td': {
|
|
74
80
|
backgroundColor:
|
|
75
81
|
tableRowProps?.hover !== false && getIsSomeColumnsPinned()
|
|
@@ -84,16 +90,26 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
|
84
90
|
...draggingBorders,
|
|
85
91
|
})}
|
|
86
92
|
>
|
|
87
|
-
{row?.getVisibleCells()?.map?.((cell) =>
|
|
88
|
-
|
|
89
|
-
cell
|
|
90
|
-
enableHover
|
|
91
|
-
key
|
|
92
|
-
rowIndex
|
|
93
|
-
rowRef
|
|
94
|
-
table
|
|
95
|
-
|
|
96
|
-
|
|
93
|
+
{row?.getVisibleCells()?.map?.((cell) => {
|
|
94
|
+
const props = {
|
|
95
|
+
cell,
|
|
96
|
+
enableHover: tableRowProps?.hover !== false,
|
|
97
|
+
key: cell.id,
|
|
98
|
+
rowIndex,
|
|
99
|
+
rowRef,
|
|
100
|
+
table,
|
|
101
|
+
};
|
|
102
|
+
return memoMode === 'cell' &&
|
|
103
|
+
cell.column.columnDef.columnDefType === 'data' &&
|
|
104
|
+
!draggingColumn &&
|
|
105
|
+
!draggingRow &&
|
|
106
|
+
editingCell?.id !== cell.id &&
|
|
107
|
+
editingRow?.id !== row.id ? (
|
|
108
|
+
<Memo_MRT_TableBodyCell {...props} />
|
|
109
|
+
) : (
|
|
110
|
+
<MRT_TableBodyCell {...props} />
|
|
111
|
+
);
|
|
112
|
+
})}
|
|
97
113
|
</TableRow>
|
|
98
114
|
{renderDetailPanel && !row.getIsGrouped() && (
|
|
99
115
|
<MRT_TableDetailPanel row={row} table={table} />
|
|
@@ -101,3 +117,8 @@ export const MRT_TableBodyRow: FC<Props> = ({
|
|
|
101
117
|
</>
|
|
102
118
|
);
|
|
103
119
|
};
|
|
120
|
+
|
|
121
|
+
export const Memo_MRT_TableBodyRow = memo(
|
|
122
|
+
MRT_TableBodyRow,
|
|
123
|
+
(prev, next) => prev.row === next.row,
|
|
124
|
+
);
|
|
@@ -36,7 +36,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, table }) => {
|
|
|
36
36
|
borderBottom: !row.getIsExpanded() ? 'none' : undefined,
|
|
37
37
|
pb: row.getIsExpanded() ? '1rem' : 0,
|
|
38
38
|
pt: row.getIsExpanded() ? '1rem' : 0,
|
|
39
|
-
transition: 'all
|
|
39
|
+
transition: 'all 150ms ease-in-out',
|
|
40
40
|
width: `${table.getTotalSize()}px`,
|
|
41
41
|
...(tableCellProps?.sx instanceof Function
|
|
42
42
|
? tableCellProps.sx(theme)
|
|
@@ -46,7 +46,7 @@ export const MRT_GrabHandleButton = <TData extends Record<string, any> = {}>({
|
|
|
46
46
|
m: 0,
|
|
47
47
|
opacity: 0.5,
|
|
48
48
|
p: '2px',
|
|
49
|
-
transition: 'all
|
|
49
|
+
transition: 'all 150ms ease-in-out',
|
|
50
50
|
'&:hover': {
|
|
51
51
|
backgroundColor: 'transparent',
|
|
52
52
|
opacity: 1,
|
package/src/column.utils.ts
CHANGED
|
@@ -234,7 +234,7 @@ export const getCommonCellStyles = ({
|
|
|
234
234
|
column.getIsPinned() === 'right'
|
|
235
235
|
? `${getTotalRight(table, column)}px`
|
|
236
236
|
: undefined,
|
|
237
|
-
transition: `all ${column.getIsResizing() ? 0 : '
|
|
237
|
+
transition: `all ${column.getIsResizing() ? 0 : '150ms'} ease-in-out`,
|
|
238
238
|
...(tableCellProps?.sx instanceof Function
|
|
239
239
|
? tableCellProps.sx(theme)
|
|
240
240
|
: (tableCellProps?.sx as any)),
|
|
@@ -66,7 +66,7 @@ export const MRT_TableHeadCellColumnActionsButton: FC<Props> = ({
|
|
|
66
66
|
height: '2rem',
|
|
67
67
|
mt: '-0.2rem',
|
|
68
68
|
opacity: 0.5,
|
|
69
|
-
transition: 'opacity
|
|
69
|
+
transition: 'opacity 150ms',
|
|
70
70
|
width: '2rem',
|
|
71
71
|
'&:hover': {
|
|
72
72
|
opacity: 1,
|
|
@@ -80,12 +80,14 @@ export const MRT_TableHeadCellColumnActionsButton: FC<Props> = ({
|
|
|
80
80
|
<MoreVertIcon />
|
|
81
81
|
</IconButton>
|
|
82
82
|
</Tooltip>
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
83
|
+
{anchorEl && (
|
|
84
|
+
<MRT_ColumnActionMenu
|
|
85
|
+
anchorEl={anchorEl}
|
|
86
|
+
header={header}
|
|
87
|
+
setAnchorEl={setAnchorEl}
|
|
88
|
+
table={table}
|
|
89
|
+
/>
|
|
90
|
+
)}
|
|
89
91
|
</>
|
|
90
92
|
);
|
|
91
93
|
};
|
|
@@ -32,7 +32,9 @@ export const MRT_TableHeadCellResizeHandle: FC<Props> = ({ header, table }) => {
|
|
|
32
32
|
position: 'absolute',
|
|
33
33
|
right: '1px',
|
|
34
34
|
touchAction: 'none',
|
|
35
|
-
transition: column.getIsResizing()
|
|
35
|
+
transition: column.getIsResizing()
|
|
36
|
+
? undefined
|
|
37
|
+
: 'all 150ms ease-in-out',
|
|
36
38
|
userSelect: 'none',
|
|
37
39
|
zIndex: 4,
|
|
38
40
|
'&:active': {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { FC } from 'react';
|
|
2
|
-
import { Checkbox, Tooltip } from '@mui/material';
|
|
1
|
+
import React, { FC, MouseEvent } from 'react';
|
|
2
|
+
import { Checkbox, Tooltip, Radio, Theme } from '@mui/material';
|
|
3
3
|
import type { MRT_Row, MRT_TableInstance } from '..';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
@@ -13,6 +13,7 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, table }) => {
|
|
|
13
13
|
getState,
|
|
14
14
|
options: {
|
|
15
15
|
localization,
|
|
16
|
+
enableMultiRowSelection,
|
|
16
17
|
muiSelectCheckboxProps,
|
|
17
18
|
muiSelectAllCheckboxProps,
|
|
18
19
|
selectAllMode,
|
|
@@ -28,6 +29,39 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, table }) => {
|
|
|
28
29
|
? muiSelectCheckboxProps({ row, table })
|
|
29
30
|
: muiSelectCheckboxProps;
|
|
30
31
|
|
|
32
|
+
const commonProps = {
|
|
33
|
+
checked: selectAll
|
|
34
|
+
? selectAllMode === 'page'
|
|
35
|
+
? table.getIsAllPageRowsSelected()
|
|
36
|
+
: table.getIsAllRowsSelected()
|
|
37
|
+
: row?.getIsSelected(),
|
|
38
|
+
inputProps: {
|
|
39
|
+
'aria-label': selectAll
|
|
40
|
+
? localization.toggleSelectAll
|
|
41
|
+
: localization.toggleSelectRow,
|
|
42
|
+
},
|
|
43
|
+
onChange: row
|
|
44
|
+
? row.getToggleSelectedHandler()
|
|
45
|
+
: selectAllMode === 'all'
|
|
46
|
+
? table.getToggleAllRowsSelectedHandler()
|
|
47
|
+
: table.getToggleAllPageRowsSelectedHandler(),
|
|
48
|
+
size: (density === 'compact' ? 'small' : 'medium') as 'small' | 'medium',
|
|
49
|
+
...checkboxProps,
|
|
50
|
+
onClick: (e: MouseEvent<HTMLButtonElement>) => {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
checkboxProps?.onClick?.(e);
|
|
53
|
+
},
|
|
54
|
+
sx: (theme: Theme) => ({
|
|
55
|
+
height: density === 'compact' ? '1.75rem' : '2.5rem',
|
|
56
|
+
width: density === 'compact' ? '1.75rem' : '2.5rem',
|
|
57
|
+
m: density !== 'compact' ? '-0.4rem' : undefined,
|
|
58
|
+
...(checkboxProps?.sx instanceof Function
|
|
59
|
+
? checkboxProps.sx(theme)
|
|
60
|
+
: (checkboxProps?.sx as any)),
|
|
61
|
+
}),
|
|
62
|
+
title: undefined,
|
|
63
|
+
};
|
|
64
|
+
|
|
31
65
|
return (
|
|
32
66
|
<Tooltip
|
|
33
67
|
arrow
|
|
@@ -40,50 +74,21 @@ export const MRT_SelectCheckbox: FC<Props> = ({ row, selectAll, table }) => {
|
|
|
40
74
|
: localization.toggleSelectRow)
|
|
41
75
|
}
|
|
42
76
|
>
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
}
|
|
59
|
-
inputProps={{
|
|
60
|
-
'aria-label': selectAll
|
|
61
|
-
? localization.toggleSelectAll
|
|
62
|
-
: localization.toggleSelectRow,
|
|
63
|
-
}}
|
|
64
|
-
onChange={
|
|
65
|
-
row
|
|
66
|
-
? row.getToggleSelectedHandler()
|
|
67
|
-
: selectAllMode === 'all'
|
|
68
|
-
? table.getToggleAllRowsSelectedHandler()
|
|
69
|
-
: table.getToggleAllPageRowsSelectedHandler()
|
|
70
|
-
}
|
|
71
|
-
size={density === 'compact' ? 'small' : 'medium'}
|
|
72
|
-
{...checkboxProps}
|
|
73
|
-
onClick={(e) => {
|
|
74
|
-
e.stopPropagation();
|
|
75
|
-
checkboxProps?.onClick?.(e);
|
|
76
|
-
}}
|
|
77
|
-
sx={(theme) => ({
|
|
78
|
-
height: density === 'compact' ? '1.75rem' : '2.5rem',
|
|
79
|
-
width: density === 'compact' ? '1.75rem' : '2.5rem',
|
|
80
|
-
m: density !== 'compact' ? '-0.4rem' : undefined,
|
|
81
|
-
...(checkboxProps?.sx instanceof Function
|
|
82
|
-
? checkboxProps.sx(theme)
|
|
83
|
-
: (checkboxProps?.sx as any)),
|
|
84
|
-
})}
|
|
85
|
-
title={undefined}
|
|
86
|
-
/>
|
|
77
|
+
{enableMultiRowSelection === false ? (
|
|
78
|
+
<Radio {...commonProps} />
|
|
79
|
+
) : (
|
|
80
|
+
<Checkbox
|
|
81
|
+
indeterminate={
|
|
82
|
+
selectAll
|
|
83
|
+
? table.getIsSomeRowsSelected() &&
|
|
84
|
+
!(selectAllMode === 'page'
|
|
85
|
+
? table.getIsAllPageRowsSelected()
|
|
86
|
+
: table.getIsAllRowsSelected())
|
|
87
|
+
: row?.getIsSomeSelected()
|
|
88
|
+
}
|
|
89
|
+
{...commonProps}
|
|
90
|
+
/>
|
|
91
|
+
)}
|
|
87
92
|
</Tooltip>
|
|
88
93
|
);
|
|
89
94
|
};
|
package/src/table/MRT_Table.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { FC } from 'react';
|
|
2
2
|
import { Table } from '@mui/material';
|
|
3
3
|
import { MRT_TableHead } from '../head/MRT_TableHead';
|
|
4
|
-
import { MRT_TableBody } from '../body/MRT_TableBody';
|
|
4
|
+
import { Memo_MRT_TableBody, MRT_TableBody } from '../body/MRT_TableBody';
|
|
5
5
|
import { MRT_TableFooter } from '../footer/MRT_TableFooter';
|
|
6
6
|
import { MRT_TableInstance } from '..';
|
|
7
7
|
|
|
@@ -18,6 +18,7 @@ export const MRT_Table: FC<Props> = ({ table }) => {
|
|
|
18
18
|
enableStickyHeader,
|
|
19
19
|
enableTableFooter,
|
|
20
20
|
enableTableHead,
|
|
21
|
+
memoMode,
|
|
21
22
|
muiTableProps,
|
|
22
23
|
},
|
|
23
24
|
} = table;
|
|
@@ -43,7 +44,11 @@ export const MRT_Table: FC<Props> = ({ table }) => {
|
|
|
43
44
|
})}
|
|
44
45
|
>
|
|
45
46
|
{enableTableHead && <MRT_TableHead table={table} />}
|
|
46
|
-
|
|
47
|
+
{memoMode === 'table-body' ? (
|
|
48
|
+
<Memo_MRT_TableBody table={table} />
|
|
49
|
+
) : (
|
|
50
|
+
<MRT_TableBody table={table} />
|
|
51
|
+
)}
|
|
47
52
|
{enableTableFooter && <MRT_TableFooter table={table} />}
|
|
48
53
|
</Table>
|
|
49
54
|
);
|
|
@@ -40,7 +40,7 @@ export const MRT_TablePaper: FC<Props> = ({ table }) => {
|
|
|
40
40
|
}
|
|
41
41
|
}}
|
|
42
42
|
sx={(theme) => ({
|
|
43
|
-
transition: 'all
|
|
43
|
+
transition: 'all 150ms ease-in-out',
|
|
44
44
|
...(tablePaperProps?.sx instanceof Function
|
|
45
45
|
? tablePaperProps?.sx(theme)
|
|
46
46
|
: (tablePaperProps?.sx as any)),
|
|
@@ -164,7 +164,7 @@ export const MRT_TableRoot = <TData extends Record<string, any> = {}>(
|
|
|
164
164
|
<MRT_SelectCheckbox row={row as any} table={table as any} />
|
|
165
165
|
),
|
|
166
166
|
Header: () =>
|
|
167
|
-
props.enableSelectAll ? (
|
|
167
|
+
props.enableSelectAll && props.enableMultiRowSelection ? (
|
|
168
168
|
<MRT_SelectCheckbox selectAll table={table as any} />
|
|
169
169
|
) : null,
|
|
170
170
|
header: props.localization.select,
|