material-react-table 0.9.2 → 0.9.5

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.2",
2
+ "version": "0.9.5",
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.",
@@ -767,6 +767,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
767
767
  IconButtonProps & { tableInstance: MRT_TableInstance<D> }
768
768
  >;
769
769
  }) => ReactNode;
770
+ rowNumberMode?: 'original' | 'static';
770
771
  selectAllMode?: 'all' | 'page';
771
772
  tableId?: string;
772
773
  };
@@ -774,7 +775,7 @@ export type MaterialReactTableProps<D extends Record<string, any> = {}> =
774
775
  export default <D extends Record<string, any> = {}>({
775
776
  autoResetExpanded = false,
776
777
  columnResizeMode = 'onEnd',
777
- defaultColumn = { minSize: 50, maxSize: 1000, size: 150 },
778
+ defaultColumn = { minSize: 30, maxSize: 1000, size: 180 },
778
779
  editingMode = 'row',
779
780
  enableColumnActions = true,
780
781
  enableColumnFilters = true,
@@ -806,6 +807,7 @@ export default <D extends Record<string, any> = {}>({
806
807
  positionGlobalFilter = 'right',
807
808
  positionToolbarActions = 'top',
808
809
  positionToolbarAlertBanner = 'top',
810
+ rowNumberMode = 'original',
809
811
  selectAllMode = 'all',
810
812
  ...rest
811
813
  }: MaterialReactTableProps<D>) => (
@@ -844,6 +846,7 @@ export default <D extends Record<string, any> = {}>({
844
846
  positionPagination={positionPagination}
845
847
  positionToolbarActions={positionToolbarActions}
846
848
  positionToolbarAlertBanner={positionToolbarAlertBanner}
849
+ rowNumberMode={rowNumberMode}
847
850
  selectAllMode={selectAllMode}
848
851
  {...rest}
849
852
  />
@@ -1,8 +1,8 @@
1
1
  import React, { FC, RefObject } from 'react';
2
+ import { useVirtual } from 'react-virtual';
2
3
  import { TableBody } from '@mui/material';
3
4
  import { MRT_TableBodyRow } from './MRT_TableBodyRow';
4
- import { MRT_Row, MRT_TableInstance } from '..';
5
- import { useVirtual } from 'react-virtual';
5
+ import type { MRT_Row, MRT_TableInstance } from '..';
6
6
 
7
7
  interface Props {
8
8
  tableInstance: MRT_TableInstance;
@@ -31,16 +31,18 @@ export const MRT_TableBody: FC<Props> = ({
31
31
  ? getPaginationRowModel().rows
32
32
  : getPrePaginationRowModel().rows;
33
33
 
34
- const rowVirtualizer = useVirtual({
35
- overscan: isDensePadding ? 15 : 5,
36
- size: rows.length,
37
- parentRef: tableContainerRef,
38
- });
34
+ const rowVirtualizer = enableRowVirtualization
35
+ ? useVirtual({
36
+ overscan: isDensePadding ? 15 : 5,
37
+ size: rows.length,
38
+ parentRef: tableContainerRef,
39
+ })
40
+ : ({} as any);
39
41
 
40
42
  const { virtualItems: virtualRows } = rowVirtualizer;
41
- const paddingTop = virtualRows.length > 0 ? virtualRows[0].start : 0;
43
+ const paddingTop = virtualRows?.length > 0 ? virtualRows[0].start : 0;
42
44
  const paddingBottom =
43
- virtualRows.length > 0
45
+ virtualRows?.length > 0
44
46
  ? rowVirtualizer.totalSize - virtualRows[virtualRows.length - 1].end
45
47
  : 0;
46
48
 
@@ -53,7 +55,7 @@ export const MRT_TableBody: FC<Props> = ({
53
55
  )}
54
56
  {/* @ts-ignore */}
55
57
  {(enableRowVirtualization ? virtualRows : rows).map(
56
- (rowOrVirtualRow: any) => {
58
+ (rowOrVirtualRow: any, rowIndex: number) => {
57
59
  const row = enableRowVirtualization
58
60
  ? (rows[rowOrVirtualRow.index] as MRT_Row)
59
61
  : (rowOrVirtualRow as MRT_Row);
@@ -61,6 +63,9 @@ export const MRT_TableBody: FC<Props> = ({
61
63
  <MRT_TableBodyRow
62
64
  key={row.id}
63
65
  row={row}
66
+ rowIndex={
67
+ enableRowVirtualization ? rowOrVirtualRow.index : rowIndex
68
+ }
64
69
  tableInstance={tableInstance}
65
70
  />
66
71
  );
@@ -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 {
@@ -24,10 +26,12 @@ export const MRT_TableBodyCell: FC<Props> = ({
24
26
  enableClickToCopy,
25
27
  enableColumnOrdering,
26
28
  enableEditing,
27
- tableId,
29
+ enableRowNumbers,
28
30
  muiTableBodyCellProps,
29
31
  muiTableBodyCellSkeletonProps,
30
32
  onMrtCellClick,
33
+ rowNumberMode,
34
+ tableId,
31
35
  },
32
36
  setColumnOrder,
33
37
  setCurrentEditingCell,
@@ -149,6 +153,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
149
153
  column.getIsPinned() === 'left'
150
154
  ? `${column.getStart('left')}px`
151
155
  : undefined,
156
+ overflow: 'hidden',
152
157
  p: isDensePadding
153
158
  ? columnDefType === 'display'
154
159
  ? '0 0.5rem'
@@ -163,6 +168,7 @@ export const MRT_TableBodyCell: FC<Props> = ({
163
168
  position: column.getIsPinned() ? 'sticky' : 'relative',
164
169
  right:
165
170
  column.getIsPinned() === 'right' ? `${getTotalRight()}px` : undefined,
171
+ textOverflow: columnDefType !== 'display' ? 'ellipsis' : undefined,
166
172
  transition: 'all 0.2s ease-in-out',
167
173
  whiteSpace: isDensePadding ? 'nowrap' : 'normal',
168
174
  zIndex: column.getIsPinned() ? 1 : undefined,
@@ -193,6 +199,10 @@ export const MRT_TableBodyCell: FC<Props> = ({
193
199
  width={skeletonWidth}
194
200
  {...muiTableBodyCellSkeletonProps}
195
201
  />
202
+ ) : enableRowNumbers &&
203
+ rowNumberMode === 'static' &&
204
+ column.id === 'mrt-row-numbers' ? (
205
+ rowIndex + 1
196
206
  ) : columnDefType === 'display' ? (
197
207
  columnDef.Cell?.({ cell, tableInstance })
198
208
  ) : 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
  ))}
@@ -10,12 +10,11 @@ interface Props {
10
10
  tableInstance: MRT_TableInstance;
11
11
  }
12
12
 
13
- export const MRT_Table: FC<Props> = ({
14
- tableContainerRef,
15
- tableInstance
16
- }) => {
13
+ export const MRT_Table: FC<Props> = ({ tableContainerRef, tableInstance }) => {
17
14
  const {
18
15
  options: {
16
+ enableColumnResizing,
17
+ enableRowVirtualization,
19
18
  enableStickyHeader,
20
19
  enableTableFooter,
21
20
  enableTableHead,
@@ -29,7 +28,15 @@ export const MRT_Table: FC<Props> = ({
29
28
  : muiTableProps;
30
29
 
31
30
  return (
32
- <Table stickyHeader={enableStickyHeader} {...tableProps}>
31
+ <Table
32
+ stickyHeader={enableStickyHeader}
33
+ {...tableProps}
34
+ sx={{
35
+ tableLayout:
36
+ enableColumnResizing || enableRowVirtualization ? 'fixed' : undefined,
37
+ ...tableProps?.sx,
38
+ }}
39
+ >
33
40
  {enableTableHead && <MRT_TableHead tableInstance={tableInstance} />}
34
41
  <MRT_TableBody
35
42
  tableContainerRef={tableContainerRef}
@@ -58,7 +58,7 @@ export const MRT_ToolbarBottom: FC<Props> = ({ tableInstance }) => {
58
58
  } as any)
59
59
  }
60
60
  >
61
- <MRT_LinearProgressBar alignTo='top' tableInstance={tableInstance} />
61
+ <MRT_LinearProgressBar alignTo="top" tableInstance={tableInstance} />
62
62
  {positionToolbarAlertBanner === 'bottom' && (
63
63
  <MRT_ToolbarAlertBanner tableInstance={tableInstance} />
64
64
  )}