material-react-table 1.9.4 → 1.10.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/index.js +42 -31
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/MaterialReactTable.d.ts +4 -0
- package/dist/cjs/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/cjs/types/column.utils.d.ts +1 -1
- package/dist/esm/material-react-table.esm.js +42 -31
- package/dist/esm/material-react-table.esm.js.map +1 -1
- package/dist/esm/types/MaterialReactTable.d.ts +4 -0
- package/dist/esm/types/body/MRT_TableDetailPanel.d.ts +2 -1
- package/dist/esm/types/column.utils.d.ts +1 -1
- package/dist/index.d.ts +4 -0
- package/package.json +5 -3
- package/src/MaterialReactTable.tsx +4 -0
- package/src/body/MRT_TableBody.tsx +22 -17
- package/src/body/MRT_TableBodyRow.tsx +2 -1
- package/src/body/MRT_TableDetailPanel.tsx +3 -1
- package/src/column.utils.ts +95 -83
- package/src/toolbar/MRT_ToolbarDropZone.tsx +1 -0
@@ -567,6 +567,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
567
567
|
muiTableBodyRowProps?: TableRowProps | ((props: {
|
568
568
|
isDetailPanel?: boolean;
|
569
569
|
row: MRT_Row<TData>;
|
570
|
+
staticRowIndex: number;
|
570
571
|
table: MRT_TableInstance<TData>;
|
571
572
|
}) => TableRowProps);
|
572
573
|
muiTableContainerProps?: TableContainerProps | ((props: {
|
@@ -691,6 +692,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> = Pr
|
|
691
692
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
692
693
|
table: MRT_TableInstance<TData>;
|
693
694
|
}) => ReactNode[];
|
695
|
+
renderEmptyRowsFallback?: (props: {
|
696
|
+
table: MRT_TableInstance<TData>;
|
697
|
+
}) => ReactNode;
|
694
698
|
renderRowActionMenuItems?: (props: {
|
695
699
|
closeMenu: () => void;
|
696
700
|
row: MRT_Row<TData>;
|
@@ -4,8 +4,9 @@ import type { MRT_Row, MRT_TableInstance } from '..';
|
|
4
4
|
interface Props {
|
5
5
|
parentRowRef: React.RefObject<HTMLTableRowElement>;
|
6
6
|
row: MRT_Row;
|
7
|
+
rowIndex: number;
|
7
8
|
table: MRT_TableInstance;
|
8
9
|
virtualRow?: VirtualItem;
|
9
10
|
}
|
10
|
-
export declare const MRT_TableDetailPanel: ({ parentRowRef, row, table, virtualRow, }: Props) => JSX.Element;
|
11
|
+
export declare const MRT_TableDetailPanel: ({ parentRowRef, row, rowIndex, table, virtualRow, }: Props) => JSX.Element;
|
11
12
|
export {};
|
@@ -103,7 +103,7 @@ export declare const prepareColumns: <TData extends Record<string, any> = {}>({
|
|
103
103
|
export declare const reorderColumn: <TData extends Record<string, any> = {}>(draggedColumn: MRT_Column<TData>, targetColumn: MRT_Column<TData>, columnOrder: MRT_ColumnOrderState) => MRT_ColumnOrderState;
|
104
104
|
export declare const showExpandColumn: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>, grouping?: MRT_GroupingState) => boolean;
|
105
105
|
export declare const getLeadingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => MRT_DisplayColumnIds[];
|
106
|
-
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) =>
|
106
|
+
export declare const getTrailingDisplayColumnIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => MRT_DisplayColumnIds[];
|
107
107
|
export declare const getDefaultColumnOrderIds: <TData extends Record<string, any> = {}>(props: MaterialReactTableProps<TData>) => string[];
|
108
108
|
export declare const getDefaultColumnFilterFn: <TData extends Record<string, any> = {}>(columnDef: MRT_ColumnDef<TData>) => MRT_FilterOption;
|
109
109
|
export declare const getIsFirstColumn: (column: MRT_Column, table: MRT_TableInstance) => boolean;
|
package/dist/index.d.ts
CHANGED
@@ -688,6 +688,7 @@ type MaterialReactTableProps<TData extends Record<string, any> = {}> = Prettify<
|
|
688
688
|
muiTableBodyRowProps?: TableRowProps | ((props: {
|
689
689
|
isDetailPanel?: boolean;
|
690
690
|
row: MRT_Row<TData>;
|
691
|
+
staticRowIndex: number;
|
691
692
|
table: MRT_TableInstance<TData>;
|
692
693
|
}) => TableRowProps);
|
693
694
|
muiTableContainerProps?: TableContainerProps | ((props: {
|
@@ -812,6 +813,9 @@ type MaterialReactTableProps<TData extends Record<string, any> = {}> = Prettify<
|
|
812
813
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
813
814
|
table: MRT_TableInstance<TData>;
|
814
815
|
}) => ReactNode[];
|
816
|
+
renderEmptyRowsFallback?: (props: {
|
817
|
+
table: MRT_TableInstance<TData>;
|
818
|
+
}) => ReactNode;
|
815
819
|
renderRowActionMenuItems?: (props: {
|
816
820
|
closeMenu: () => void;
|
817
821
|
row: MRT_Row<TData>;
|
package/package.json
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
{
|
2
|
-
"version": "1.
|
2
|
+
"version": "1.10.0",
|
3
3
|
"license": "MIT",
|
4
4
|
"name": "material-react-table",
|
5
5
|
"description": "A fully featured Material UI V5 implementation of TanStack React Table V8, written from the ground up in TypeScript.",
|
@@ -48,9 +48,11 @@
|
|
48
48
|
"build": "pnpm lib:build",
|
49
49
|
"build-locales": "pnpm lib:build-locales",
|
50
50
|
"build-no-locales": "pnpm lib:build-no-locales",
|
51
|
+
"dev": "pnpm lib:dev",
|
51
52
|
"lib:build": "rm -rf dist && pnpm build-no-locales && pnpm build-locales",
|
52
|
-
"lib:build-locales": "rm -rf locales && rollup
|
53
|
-
"lib:build-no-locales": "rm -rf dist && rollup
|
53
|
+
"lib:build-locales": "rm -rf locales && rollup -c rollup-locales.config.mjs",
|
54
|
+
"lib:build-no-locales": "rm -rf dist && rollup -c rollup.config.mjs && size-limit",
|
55
|
+
"lib:dev": "rollup -c rollup.config.mjs --watch",
|
54
56
|
"lint": "eslint .",
|
55
57
|
"size": "size-limit"
|
56
58
|
},
|
@@ -776,6 +776,7 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
776
776
|
| ((props: {
|
777
777
|
isDetailPanel?: boolean;
|
778
778
|
row: MRT_Row<TData>;
|
779
|
+
staticRowIndex: number;
|
779
780
|
table: MRT_TableInstance<TData>;
|
780
781
|
}) => TableRowProps);
|
781
782
|
muiTableContainerProps?:
|
@@ -918,6 +919,9 @@ export type MaterialReactTableProps<TData extends Record<string, any> = {}> =
|
|
918
919
|
onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
|
919
920
|
table: MRT_TableInstance<TData>;
|
920
921
|
}) => ReactNode[];
|
922
|
+
renderEmptyRowsFallback?: (props: {
|
923
|
+
table: MRT_TableInstance<TData>;
|
924
|
+
}) => ReactNode;
|
921
925
|
renderRowActionMenuItems?: (props: {
|
922
926
|
closeMenu: () => void;
|
923
927
|
row: MRT_Row<TData>;
|
@@ -42,6 +42,7 @@ export const MRT_TableBody = ({
|
|
42
42
|
manualSorting,
|
43
43
|
memoMode,
|
44
44
|
muiTableBodyProps,
|
45
|
+
renderEmptyRowsFallback,
|
45
46
|
rowVirtualizerInstanceRef,
|
46
47
|
rowVirtualizerProps,
|
47
48
|
virtualizerInstanceRef,
|
@@ -163,24 +164,28 @@ export const MRT_TableBody = ({
|
|
163
164
|
<tr style={{ display: layoutMode === 'grid' ? 'grid' : 'table-row' }}>
|
164
165
|
<td
|
165
166
|
colSpan={table.getVisibleLeafColumns().length}
|
166
|
-
style={{
|
167
|
+
style={{
|
168
|
+
display: layoutMode === 'grid' ? 'grid' : 'table-cell',
|
169
|
+
}}
|
167
170
|
>
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
171
|
+
{renderEmptyRowsFallback?.({ table }) ?? (
|
172
|
+
<Typography
|
173
|
+
sx={{
|
174
|
+
color: 'text.secondary',
|
175
|
+
fontStyle: 'italic',
|
176
|
+
maxWidth: `min(100vw, ${
|
177
|
+
tablePaperRef.current?.clientWidth ?? 360
|
178
|
+
}px)`,
|
179
|
+
py: '2rem',
|
180
|
+
textAlign: 'center',
|
181
|
+
width: '100%',
|
182
|
+
}}
|
183
|
+
>
|
184
|
+
{globalFilter || columnFilters.length
|
185
|
+
? localization.noResultsFound
|
186
|
+
: localization.noRecordsToDisplay}
|
187
|
+
</Typography>
|
188
|
+
)}
|
184
189
|
</td>
|
185
190
|
</tr>
|
186
191
|
) : (
|
@@ -47,7 +47,7 @@ export const MRT_TableBodyRow = ({
|
|
47
47
|
|
48
48
|
const tableRowProps =
|
49
49
|
muiTableBodyRowProps instanceof Function
|
50
|
-
? muiTableBodyRowProps({ row, table })
|
50
|
+
? muiTableBodyRowProps({ row, staticRowIndex: rowIndex, table })
|
51
51
|
: muiTableBodyRowProps;
|
52
52
|
|
53
53
|
const handleDragEnter = (_e: DragEvent) => {
|
@@ -136,6 +136,7 @@ export const MRT_TableBodyRow = ({
|
|
136
136
|
<MRT_TableDetailPanel
|
137
137
|
parentRowRef={rowRef}
|
138
138
|
row={row}
|
139
|
+
rowIndex={rowIndex}
|
139
140
|
table={table}
|
140
141
|
virtualRow={virtualRow}
|
141
142
|
/>
|
@@ -9,6 +9,7 @@ import type { MRT_Row, MRT_TableInstance } from '..';
|
|
9
9
|
interface Props {
|
10
10
|
parentRowRef: React.RefObject<HTMLTableRowElement>;
|
11
11
|
row: MRT_Row;
|
12
|
+
rowIndex: number;
|
12
13
|
table: MRT_TableInstance;
|
13
14
|
virtualRow?: VirtualItem;
|
14
15
|
}
|
@@ -16,6 +17,7 @@ interface Props {
|
|
16
17
|
export const MRT_TableDetailPanel = ({
|
17
18
|
parentRowRef,
|
18
19
|
row,
|
20
|
+
rowIndex,
|
19
21
|
table,
|
20
22
|
virtualRow,
|
21
23
|
}: Props) => {
|
@@ -33,7 +35,7 @@ export const MRT_TableDetailPanel = ({
|
|
33
35
|
|
34
36
|
const tableRowProps =
|
35
37
|
muiTableBodyRowProps instanceof Function
|
36
|
-
? muiTableBodyRowProps({ isDetailPanel: true, row, table })
|
38
|
+
? muiTableBodyRowProps({ isDetailPanel: true, row, staticRowIndex: rowIndex, table })
|
37
39
|
: muiTableBodyRowProps;
|
38
40
|
|
39
41
|
const tableCellProps =
|
package/src/column.utils.ts
CHANGED
@@ -164,29 +164,34 @@ export const getTrailingDisplayColumnIds = <
|
|
164
164
|
TData extends Record<string, any> = {},
|
165
165
|
>(
|
166
166
|
props: MaterialReactTableProps<TData>,
|
167
|
-
) =>
|
168
|
-
|
169
|
-
|
170
|
-
(props.
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
167
|
+
) =>
|
168
|
+
[
|
169
|
+
props.positionActionsColumn === 'last' &&
|
170
|
+
(props.enableRowActions ||
|
171
|
+
(props.enableEditing &&
|
172
|
+
['row', 'modal'].includes(props.editingMode ?? ''))) &&
|
173
|
+
'mrt-row-actions',
|
174
|
+
props.positionExpandColumn === 'last' &&
|
175
|
+
showExpandColumn(props) &&
|
176
|
+
'mrt-row-expand',
|
177
|
+
].filter(Boolean) as MRT_DisplayColumnIds[];
|
177
178
|
|
178
179
|
export const getDefaultColumnOrderIds = <
|
179
180
|
TData extends Record<string, any> = {},
|
180
181
|
>(
|
181
182
|
props: MaterialReactTableProps<TData>,
|
182
|
-
) =>
|
183
|
-
[
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
183
|
+
) => {
|
184
|
+
const leadingDisplayCols: string[] = getLeadingDisplayColumnIds(props);
|
185
|
+
const trailingDisplayCols: string[] = getTrailingDisplayColumnIds(props);
|
186
|
+
const allLeafColumnDefs = getAllLeafColumnDefs(props.columns)
|
187
|
+
.map((columnDef) => getColumnId(columnDef))
|
188
|
+
.filter(
|
189
|
+
(columnId) =>
|
190
|
+
!leadingDisplayCols.includes(columnId) &&
|
191
|
+
!trailingDisplayCols.includes(columnId),
|
192
|
+
);
|
193
|
+
return [...leadingDisplayCols, ...allLeafColumnDefs, ...trailingDisplayCols];
|
194
|
+
};
|
190
195
|
|
191
196
|
export const getDefaultColumnFilterFn = <
|
192
197
|
TData extends Record<string, any> = {},
|
@@ -250,72 +255,79 @@ export const getCommonCellStyles = ({
|
|
250
255
|
table: MRT_TableInstance;
|
251
256
|
tableCellProps: TableCellProps;
|
252
257
|
theme: Theme;
|
253
|
-
}) =>
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
:
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
:
|
271
|
-
|
272
|
-
column.getIsPinned() === 'left'
|
273
|
-
? `${column.getStart('left')}px`
|
274
|
-
: undefined,
|
275
|
-
ml:
|
276
|
-
table.options.enableColumnVirtualization &&
|
277
|
-
column.getIsPinned() === 'left' &&
|
278
|
-
column.getPinnedIndex() === 0
|
279
|
-
? `-${
|
280
|
-
column.getSize() * (table.getState().columnPinning.left?.length ?? 1)
|
281
|
-
}px`
|
282
|
-
: undefined,
|
283
|
-
mr:
|
284
|
-
table.options.enableColumnVirtualization &&
|
285
|
-
column.getIsPinned() === 'right' &&
|
286
|
-
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
287
|
-
? `-${
|
288
|
-
column.getSize() *
|
289
|
-
(table.getState().columnPinning.right?.length ?? 1) *
|
290
|
-
1.2
|
291
|
-
}px`
|
292
|
-
: undefined,
|
293
|
-
opacity:
|
294
|
-
table.getState().draggingColumn?.id === column.id ||
|
295
|
-
table.getState().hoveredColumn?.id === column.id
|
296
|
-
? 0.5
|
297
|
-
: 1,
|
298
|
-
position:
|
299
|
-
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
300
|
-
? 'sticky'
|
301
|
-
: undefined,
|
302
|
-
right:
|
303
|
-
column.getIsPinned() === 'right'
|
304
|
-
? `${getTotalRight(table, column)}px`
|
258
|
+
}) => {
|
259
|
+
const widthStyles = {
|
260
|
+
minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
261
|
+
header?.id ?? column.id,
|
262
|
+
)}-size) * 1px), ${column.columnDef.minSize ?? 30}px)`,
|
263
|
+
width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
264
|
+
header?.id ?? column.id,
|
265
|
+
)}-size) * 1px)`,
|
266
|
+
};
|
267
|
+
return {
|
268
|
+
backgroundColor:
|
269
|
+
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
270
|
+
? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
|
271
|
+
: 'inherit',
|
272
|
+
backgroundImage: 'inherit',
|
273
|
+
boxShadow: getIsLastLeftPinnedColumn(table, column)
|
274
|
+
? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
275
|
+
: getIsFirstRightPinnedColumn(column)
|
276
|
+
? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
|
305
277
|
: undefined,
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
278
|
+
display: table.options.layoutMode === 'grid' ? 'flex' : 'table-cell',
|
279
|
+
flex:
|
280
|
+
table.options.layoutMode === 'grid'
|
281
|
+
? `var(--${header ? 'header' : 'col'}-${parseCSSVarId(
|
282
|
+
header?.id ?? column.id,
|
283
|
+
)}-size) 0 auto`
|
284
|
+
: undefined,
|
285
|
+
left:
|
286
|
+
column.getIsPinned() === 'left'
|
287
|
+
? `${column.getStart('left')}px`
|
288
|
+
: undefined,
|
289
|
+
ml:
|
290
|
+
table.options.enableColumnVirtualization &&
|
291
|
+
column.getIsPinned() === 'left' &&
|
292
|
+
column.getPinnedIndex() === 0
|
293
|
+
? `-${
|
294
|
+
column.getSize() *
|
295
|
+
(table.getState().columnPinning.left?.length ?? 1)
|
296
|
+
}px`
|
297
|
+
: undefined,
|
298
|
+
mr:
|
299
|
+
table.options.enableColumnVirtualization &&
|
300
|
+
column.getIsPinned() === 'right' &&
|
301
|
+
column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
|
302
|
+
? `-${
|
303
|
+
column.getSize() *
|
304
|
+
(table.getState().columnPinning.right?.length ?? 1) *
|
305
|
+
1.2
|
306
|
+
}px`
|
307
|
+
: undefined,
|
308
|
+
opacity:
|
309
|
+
table.getState().draggingColumn?.id === column.id ||
|
310
|
+
table.getState().hoveredColumn?.id === column.id
|
311
|
+
? 0.5
|
312
|
+
: 1,
|
313
|
+
position:
|
314
|
+
column.getIsPinned() && column.columnDef.columnDefType !== 'group'
|
315
|
+
? 'sticky'
|
316
|
+
: undefined,
|
317
|
+
right:
|
318
|
+
column.getIsPinned() === 'right'
|
319
|
+
? `${getTotalRight(table, column)}px`
|
320
|
+
: undefined,
|
321
|
+
transition: table.options.enableColumnVirtualization
|
322
|
+
? 'none'
|
323
|
+
: `padding 150ms ease-in-out`,
|
324
|
+
...(!table.options.enableColumnResizing && widthStyles), //let devs pass in width styles if column resizing is disabled
|
325
|
+
...(tableCellProps?.sx instanceof Function
|
326
|
+
? tableCellProps.sx(theme)
|
327
|
+
: (tableCellProps?.sx as any)),
|
328
|
+
...(table.options.enableColumnResizing && widthStyles), //don't let devs pass in width styles if column resizing is enabled
|
329
|
+
};
|
330
|
+
};
|
319
331
|
|
320
332
|
export const MRT_DefaultColumn = {
|
321
333
|
filterVariant: 'text',
|