material-react-table 1.5.0-beta.1 → 1.5.0-beta.2

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-beta.2",
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,26 @@ 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() *
262
+ (table.getState().columnPinning.left?.length ?? 1) *
263
+ 1.2
264
+ }px`
265
+ : undefined,
266
+ mr:
267
+ table.options.enableColumnVirtualization &&
268
+ column.getIsPinned() === 'right' &&
269
+ column.getPinnedIndex() === table.getVisibleLeafColumns().length - 1
270
+ ? `-${
271
+ column.getSize() *
272
+ (table.getState().columnPinning.right?.length ?? 1) *
273
+ 1.2
274
+ }px`
275
+ : undefined,
256
276
  opacity:
257
277
  table.getState().draggingColumn?.id === column.id ||
258
278
  table.getState().hoveredColumn?.id === column.id
@@ -52,25 +52,23 @@ export const MRT_Table: FC<Props> = ({ table }) => {
52
52
  .getRowModel()
53
53
  .rows[0]?.getCenterVisibleCells()
54
54
  ?.slice(0, 16)
55
- ?.map((cell) => cell.column.getSize() * 1.25) ?? [];
55
+ ?.map((cell) => cell.column.getSize() * 1.2) ?? [];
56
56
  return columnsWidths.reduce((a, b) => a + b, 0) / columnsWidths.length;
57
57
  }, [table.getRowModel().rows, columnPinning, columnVisibility]);
58
58
 
59
- const pinnedColumnIndexes = useMemo(
59
+ const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
60
60
  () =>
61
61
  enableColumnVirtualization && enablePinning
62
62
  ? [
63
- ...table.getLeftFlatHeaders().map((h) => h.column.getPinnedIndex()),
64
- ...table
65
- .getRightFlatHeaders()
63
+ table.getLeftLeafColumns().map((c) => c.getPinnedIndex()),
64
+ table
65
+ .getRightLeafColumns()
66
66
  .map(
67
- (h) =>
68
- table.getVisibleFlatColumns().length -
69
- h.column.getPinnedIndex() -
70
- 1,
67
+ (c) =>
68
+ table.getVisibleLeafColumns().length - c.getPinnedIndex() - 1,
71
69
  ),
72
70
  ]
73
- : [],
71
+ : [[], []],
74
72
  [columnPinning, enableColumnVirtualization, enablePinning],
75
73
  );
76
74
 
@@ -78,21 +76,20 @@ export const MRT_Table: FC<Props> = ({ table }) => {
78
76
  | Virtualizer<HTMLDivElement, HTMLTableCellElement>
79
77
  | undefined = enableColumnVirtualization
80
78
  ? useVirtualizer({
81
- count: table.getRowModel().rows[0].getVisibleCells().length,
79
+ count: table.getVisibleLeafColumns().length,
82
80
  estimateSize: () => averageColumnWidth,
83
81
  getScrollElement: () => tableContainerRef.current,
84
82
  horizontal: true,
85
- measureElement: (element) => element?.getBoundingClientRect().width,
86
83
  overscan: 3,
87
84
  rangeExtractor: useCallback(
88
- (range: Range) =>
89
- [
90
- ...new Set([
91
- ...pinnedColumnIndexes,
92
- ...defaultRangeExtractor(range),
93
- ]),
94
- ].sort((a, b) => a - b),
95
- [pinnedColumnIndexes],
85
+ (range: Range) => [
86
+ ...new Set([
87
+ ...leftPinnedIndexes,
88
+ ...defaultRangeExtractor(range),
89
+ ...rightPinnedIndexes,
90
+ ]),
91
+ ],
92
+ [leftPinnedIndexes, rightPinnedIndexes],
96
93
  ),
97
94
  ...vProps,
98
95
  })
@@ -110,13 +107,11 @@ export const MRT_Table: FC<Props> = ({ table }) => {
110
107
  let virtualPaddingRight: number | undefined;
111
108
 
112
109
  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;
110
+ virtualPaddingLeft = virtualColumns[leftPinnedIndexes.length]?.start ?? 0;
111
+ virtualPaddingRight =
112
+ columnVirtualizer.getTotalSize() -
113
+ (virtualColumns[virtualColumns.length - 1 - rightPinnedIndexes.length]
114
+ ?.end ?? 0);
120
115
  }
121
116
 
122
117
  const props = {