material-react-table 1.5.0-beta.1 → 1.5.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/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.5.0-beta.1",
2
+ "version": "1.5.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.",
@@ -221,7 +221,7 @@ export const getIsFirstRightPinnedColumn = (column: MRT_Column) => {
221
221
 
222
222
  export const getTotalRight = (table: MRT_TableInstance, column: MRT_Column) => {
223
223
  return (
224
- (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160
224
+ (table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 200
225
225
  );
226
226
  };
227
227
 
@@ -253,6 +253,24 @@ export const getCommonCellStyles = ({
253
253
  column.getIsPinned() === 'left'
254
254
  ? `${column.getStart('left')}px`
255
255
  : undefined,
256
+ ml:
257
+ table.options.enableColumnVirtualization &&
258
+ column.getIsPinned() === 'left' &&
259
+ column.getPinnedIndex() === 0
260
+ ? `-${
261
+ column.getSize() * (table.getState().columnPinning.left?.length ?? 1)
262
+ }px`
263
+ : undefined,
264
+ mr:
265
+ table.options.enableColumnVirtualization &&
266
+ column.getIsPinned() === 'right' &&
267
+ column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
268
+ ? `-${
269
+ column.getSize() *
270
+ (table.getState().columnPinning.right?.length ?? 1) *
271
+ 1.2
272
+ }px`
273
+ : undefined,
256
274
  opacity:
257
275
  table.getState().draggingColumn?.id === column.id ||
258
276
  table.getState().hoveredColumn?.id === column.id
@@ -47,30 +47,29 @@ export const MRT_Table: FC<Props> = ({ table }) => {
47
47
 
48
48
  //get first 16 column widths and average them
49
49
  const averageColumnWidth = useMemo(() => {
50
+ if (!enableColumnVirtualization) return 0;
50
51
  const columnsWidths =
51
52
  table
52
53
  .getRowModel()
53
54
  .rows[0]?.getCenterVisibleCells()
54
55
  ?.slice(0, 16)
55
- ?.map((cell) => cell.column.getSize() * 1.25) ?? [];
56
+ ?.map((cell) => cell.column.getSize() * 1.2) ?? [];
56
57
  return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
57
58
  }, [table.getRowModel().rows, columnPinning, columnVisibility]);
58
59
 
59
- const pinnedColumnIndexes = useMemo(
60
+ const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
60
61
  () =>
61
62
  enableColumnVirtualization && enablePinning
62
63
  ? [
63
- ...table.getLeftFlatHeaders().map((h) => h.column.getPinnedIndex()),
64
- ...table
65
- .getRightFlatHeaders()
64
+ table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
65
+ table
66
+ .getRightLeafColumns()
66
67
  .map(
67
- (h) =>
68
- table.getVisibleFlatColumns().length -
69
- h.column.getPinnedIndex() -
70
- 1,
68
+ (c) =>
69
+ table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1,
71
70
  ),
72
71
  ]
73
- : [],
72
+ : [[], []],
74
73
  [columnPinning, enableColumnVirtualization, enablePinning],
75
74
  );
76
75
 
@@ -78,21 +77,20 @@ export const MRT_Table: FC<Props> = ({ table }) => {
78
77
  | Virtualizer<HTMLDivElement, HTMLTableCellElement>
79
78
  | undefined = enableColumnVirtualization
80
79
  ? useVirtualizer({
81
- count: table.getRowModel().rows[0].getVisibleCells().length,
80
+ count: table.getVisibleLeafColumns().length,
82
81
  estimateSize: () => averageColumnWidth,
83
82
  getScrollElement: () => tableContainerRef.current,
84
83
  horizontal: true,
85
- measureElement: (element) => element?.getBoundingClientRect().width,
86
84
  overscan: 3,
87
85
  rangeExtractor: useCallback(
88
- (range: Range) =>
89
- [
90
- ...new Set([
91
- ...pinnedColumnIndexes,
92
- ...defaultRangeExtractor(range),
93
- ]),
94
- ].sort((a, b) => a - b),
95
- [pinnedColumnIndexes],
86
+ (range: Range) => [
87
+ ...new Set([
88
+ ...leftPinnedIndexes,
89
+ ...defaultRangeExtractor(range),
90
+ ...rightPinnedIndexes,
91
+ ]),
92
+ ],
93
+ [leftPinnedIndexes, rightPinnedIndexes],
96
94
  ),
97
95
  ...vProps,
98
96
  })
@@ -110,13 +108,11 @@ export const MRT_Table: FC<Props> = ({ table }) => {
110
108
  let virtualPaddingRight: number | undefined;
111
109
 
112
110
  if (columnVirtualizer && virtualColumns?.length) {
113
- virtualPaddingLeft = virtualColumns?.length
114
- ? virtualColumns[0]?.start || 0
115
- : 0;
116
- virtualPaddingRight = virtualColumns?.length
117
- ? columnVirtualizer.getTotalSize() -
118
- (virtualColumns[virtualColumns.length - 1]?.end || 0)
119
- : 0;
111
+ virtualPaddingLeft = virtualColumns[leftPinnedIndexes.length]?.start ?? 0;
112
+ virtualPaddingRight =
113
+ columnVirtualizer.getTotalSize() -
114
+ (virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]
115
+ ?.end ?? 0);
120
116
  }
121
117
 
122
118
  const props = {