Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,10 @@ export const MRT_TableBody = <TData extends MRT_RowData>({
? (rowOrVirtualRow as VirtualItem)
: undefined,
};
const key = `${row.id}-${row.index}`;
return memoMode === 'rows' ? (
<Memo_MRT_TableBodyRow key={key} {...props} />
<Memo_MRT_TableBodyRow key={row.id} {...props} />
) : (
<MRT_TableBodyRow key={key} {...props} />
<MRT_TableBodyRow key={row.id} {...props} />
);
})}
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,17 +248,16 @@ export const MRT_TableBodyRow = <TData extends MRT_RowData>({
staticRowIndex,
table,
};
const key = `${cell.id}-${staticRowIndex}`;
return cell ? (
memoMode === 'cells' &&
cell.column.columnDef.columnDefType === 'data' &&
!draggingColumn &&
!draggingRow &&
editingCell?.id !== cell.id &&
editingRow?.id !== row.id ? (
<Memo_MRT_TableBodyCell key={key} {...props} />
<Memo_MRT_TableBodyCell key={cell.id} {...props} />
) : (
<MRT_TableBodyCell key={key} {...props} />
<MRT_TableBodyCell key={cell.id} {...props} />
)
) : null;
},
Expand Down
15 changes: 13 additions & 2 deletions packages/material-react-table/src/hooks/useMRT_TableInstance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,11 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
...Array(
Math.min(statefulTableOptions.state.pagination.pageSize, 20),
).fill(null),
].map(() =>
].map((_, index) =>
Object.assign(
{},
{
'mrt-skeleton-id': `skeleton-${index}`,
},
...getAllLeafColumnDefs(statefulTableOptions.columns).map(
(col) => ({
[getColumnId(col)]: null,
Expand All @@ -247,6 +249,15 @@ export const useMRT_TableInstance = <TData extends MRT_RowData>(
],
);

statefulTableOptions.getRowId = useMemo(() => {
const getRowId = statefulTableOptions.getRowId;
return (originalRow, index, parentRow) => {
if ('mrt-skeleton-id' in originalRow)
return originalRow['mrt-skeleton-id'];
return getRowId?.(originalRow, index, parentRow);
};
}, [statefulTableOptions.getRowId]);

//@ts-expect-error
const table = useReactTable({
onColumnOrderChange,
Expand Down