material-react-table 0.9.3 → 0.9.6

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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.9.3",
2
+ "version": "0.9.6",
3
3
  "license": "MIT",
4
4
  "name": "material-react-table",
5
5
  "description": "A fully featured Material UI implementation of TanStack React Table, inspired by material-table and the MUI X DataGrid, written from the ground up in TypeScript.",
@@ -43,6 +43,7 @@ import {
43
43
  UseTableInstanceOptions,
44
44
  VisibilityState,
45
45
  } from '@tanstack/react-table';
46
+ import { Options as VirtualizerOptions } from 'react-virtual';
46
47
  import { MRT_Localization, MRT_DefaultLocalization_EN } from './localization';
47
48
  import { MRT_Default_Icons, MRT_Icons } from './icons';
48
49
  import { MRT_FILTER_OPTION } from './enums';
@@ -767,14 +768,16 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
767
768
  IconButtonProps & { tableInstance: MRT_TableInstance<D> }
768
769
  >;
769
770
  }) => ReactNode;
771
+ rowNumberMode?: 'original' | 'static';
770
772
  selectAllMode?: 'all' | 'page';
771
773
  tableId?: string;
774
+ virtualizerProps?: VirtualizerOptions<HTMLDivElement>;
772
775
  };
773
776
 
774
777
  export default <D extends Record<string, any> = {}>({
775
778
  autoResetExpanded = false,
776
779
  columnResizeMode = 'onEnd',
777
- defaultColumn = { minSize: 30, maxSize: 1000, size: 180 },
780
+ defaultColumn = { minSize: 40, maxSize: 1000, size: 180 },
778
781
  editingMode = 'row',
779
782
  enableColumnActions = true,
780
783
  enableColumnFilters = true,
@@ -806,6 +809,7 @@ export default <D extends Record<string, any> = {}>({
806
809
  positionGlobalFilter = 'right',
807
810
  positionToolbarActions = 'top',
808
811
  positionToolbarAlertBanner = 'top',
812
+ rowNumberMode = 'original',
809
813
  selectAllMode = 'all',
810
814
  ...rest
811
815
  }: MaterialReactTableProps<D>) => (
@@ -844,6 +848,7 @@ export default <D extends Record<string, any> = {}>({
844
848
  positionPagination={positionPagination}
845
849
  positionToolbarActions={positionToolbarActions}
846
850
  positionToolbarAlertBanner={positionToolbarAlertBanner}
851
+ rowNumberMode={rowNumberMode}
847
852
  selectAllMode={selectAllMode}
848
853
  {...rest}
849
854
  />
@@ -17,7 +17,12 @@ export const MRT_TableBody: FC<Props> = ({
17
17
  getPaginationRowModel,
18
18
  getPrePaginationRowModel,
19
19
  getState,
20
- options: { enablePagination, enableRowVirtualization, muiTableBodyProps },
20
+ options: {
21
+ enablePagination,
22
+ enableRowVirtualization,
23
+ muiTableBodyProps,
24
+ virtualizerProps,
25
+ },
21
26
  } = tableInstance;
22
27
 
23
28
  const { isDensePadding } = getState();
@@ -36,6 +41,7 @@ export const MRT_TableBody: FC<Props> = ({
36
41
  overscan: isDensePadding ? 15 : 5,
37
42
  size: rows.length,
38
43
  parentRef: tableContainerRef,
44
+ ...virtualizerProps,
39
45
  })
40
46
  : ({} as any);
41
47
 
@@ -55,7 +61,7 @@ export const MRT_TableBody: FC<Props> = ({
55
61
  )}
56
62
  {/* @ts-ignore */}
57
63
  {(enableRowVirtualization ? virtualRows : rows).map(
58
- (rowOrVirtualRow: any) => {
64
+ (rowOrVirtualRow: any, rowIndex: number) => {
59
65
  const row = enableRowVirtualization
60
66
  ? (rows[rowOrVirtualRow.index] as MRT_Row)
61
67
  : (rowOrVirtualRow as MRT_Row);
@@ -63,6 +69,9 @@ export const MRT_TableBody: FC<Props> = ({
63
69
  <MRT_TableBodyRow
64
70
  key={row.id}
65
71
  row={row}
72
+ rowIndex={
73
+ enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
74
+ }
66
75
  tableInstance={tableInstance}
67
76
  />
68
77
  );
@@ -9,12 +9,14 @@ import type { MRT_Cell, MRT_Column, MRT_TableInstance } from '..';
9
9
  interface Props {
10
10
  cell: MRT_Cell;
11
11
  enableHover?: boolean;
12
+ rowIndex: number;
12
13
  tableInstance: MRT_TableInstance;
13
14
  }
14
15
 
15
16
  export const MRT_TableBodyCell: FC<Props> = ({
16
17
  cell,
17
18
  enableHover,
19
+ rowIndex,
18
20
  tableInstance,
19
21
  }) => {
20
22
  const {
@@ -23,12 +25,12 @@ export const MRT_TableBodyCell: FC<Props> = ({
23
25
  editingMode,
24
26
  enableClickToCopy,
25
27
  enableColumnOrdering,
26
- enableColumnResizing,
27
28
  enableEditing,
28
- enableRowVirtualization,
29
+ enableRowNumbers,
29
30
  muiTableBodyCellProps,
30
31
  muiTableBodyCellSkeletonProps,
31
32
  onMrtCellClick,
33
+ rowNumberMode,
32
34
  tableId,
33
35
  },
34
36
  setColumnOrder,
@@ -133,15 +135,6 @@ export const MRT_TableBodyCell: FC<Props> = ({
133
135
  onMrtCellClick?.({ event, cell, tableInstance })
134
136
  }
135
137
  onDoubleClick={handleDoubleClick}
136
- title={
137
- (enableRowVirtualization || enableColumnResizing) &&
138
- !columnDef?.Cell &&
139
- !cell.getIsGrouped() &&
140
- !columnDef.enableClickToCopy &&
141
- typeof cell.getValue() === 'string'
142
- ? (cell.getValue() as string)
143
- : ''
144
- }
145
138
  {...tableCellProps}
146
139
  ref={
147
140
  columnDefType === 'data' && enableColumnOrdering ? dropRef : undefined
@@ -175,7 +168,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
175
168
  position: column.getIsPinned() ? 'sticky' : 'relative',
176
169
  right:
177
170
  column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
178
- textOverflow: 'ellipsis',
171
+ textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
179
172
  transition: 'all 0.2s ease-in-out',
180
173
  whiteSpace: isDensePadding ? 'nowrap' : 'normal',
181
174
  zIndex: column.getIsPinned() ? 1 : undefined,
@@ -191,12 +184,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
191
184
  : undefined,
192
185
  },
193
186
  ...(tableCellProps?.sx as any),
194
- })}
195
- style={{
196
187
  maxWidth: `min(${column.getSize()}px, fit-content)`,
197
188
  minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
198
189
  width: column.getSize(),
199
- }}
190
+ })}
200
191
  >
201
192
  <>
202
193
  {isLoading || showSkeletons ? (
@@ -206,6 +197,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
206
197
  width={skeletonWidth}
207
198
  {...muiTableBodyCellSkeletonProps}
208
199
  />
200
+ ) : enableRowNumbers &&
201
+ rowNumberMode === 'static' &&
202
+ column.id === 'mrt-row-numbers' ? (
203
+ rowIndex + 1
209
204
  ) : columnDefType === 'display' ? (
210
205
  columnDef.Cell?.({ cell, tableInstance })
211
206
  ) : cell.getIsPlaceholder() ||
@@ -6,10 +6,11 @@ import type { MRT_Row, MRT_TableInstance } from '..';
6
6
 
7
7
  interface Props {
8
8
  row: MRT_Row;
9
+ rowIndex: number;
9
10
  tableInstance: MRT_TableInstance;
10
11
  }
11
12
 
12
- export const MRT_TableBodyRow: FC<Props> = ({ row, tableInstance }) => {
13
+ export const MRT_TableBodyRow: FC<Props> = ({ row, rowIndex, tableInstance }) => {
13
14
  const {
14
15
  getIsSomeColumnsPinned,
15
16
  options: { muiTableBodyRowProps, onMrtRowClick, renderDetailPanel },
@@ -48,6 +49,7 @@ export const MRT_TableBodyRow: FC<Props> = ({ row, tableInstance }) => {
48
49
  cell={cell}
49
50
  key={cell.id}
50
51
  enableHover={tableRowProps?.hover !== false}
52
+ rowIndex={rowIndex}
51
53
  tableInstance={tableInstance}
52
54
  />
53
55
  ))}
@@ -9,7 +9,7 @@ interface Props {
9
9
 
10
10
  export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
11
11
  const {
12
- getVisibleFlatColumns,
12
+ getVisibleLeafColumns,
13
13
  options: {
14
14
  muiTableBodyRowProps,
15
15
  muiTableDetailPanelProps,
@@ -31,7 +31,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
31
31
  return (
32
32
  <TableRow {...tableRowProps}>
33
33
  <TableCell
34
- colSpan={getVisibleFlatColumns().length + 10}
34
+ colSpan={getVisibleLeafColumns().length}
35
35
  onClick={(event: MouseEvent<HTMLTableCellElement>) =>
36
36
  onMrtDetailPanelClick?.({ event, row, tableInstance })
37
37
  }
@@ -41,6 +41,7 @@ export const MRT_TableDetailPanel: FC<Props> = ({ row, tableInstance }) => {
41
41
  pb: row.getIsExpanded() ? '1rem' : 0,
42
42
  pt: row.getIsExpanded() ? '1rem' : 0,
43
43
  transition: 'all 0.2s ease-in-out',
44
+ width: `${tableInstance.getTotalSize()}px`,
44
45
  ...tableCellProps?.sx,
45
46
  }}
46
47
  >
@@ -136,12 +136,10 @@ export const MRT_TableHeadCell: FC<Props> = ({
136
136
  ? 2
137
137
  : 1,
138
138
  ...(tableCellProps?.sx as any),
139
- })}
140
- style={{
141
139
  maxWidth: `min(${column.getSize()}px, fit-content)`,
142
140
  minWidth: `max(${column.getSize()}px, ${columnDef.minSize ?? 30}px)`,
143
141
  width: header.getSize(),
144
- }}
142
+ })}
145
143
  >
146
144
  {header.isPlaceholder ? null : columnDefType === 'display' ? (
147
145
  headerElement
@@ -33,7 +33,7 @@ export const MRT_Table: FC<Props> = ({ tableContainerRef, tableInstance }) => {
33
33
  {...tableProps}
34
34
  sx={{
35
35
  tableLayout:
36
- enableColumnResizing || enableRowVirtualization ? 'fixed' : undefined,
36
+ enableColumnResizing || enableRowVirtualization ? 'fixed' : 'auto',
37
37
  ...tableProps?.sx,
38
38
  }}
39
39
  >