Skip to content

Commit

Permalink
feat: updated row position row model (#302)
Browse files Browse the repository at this point in the history
  • Loading branch information
Fran McDade authored and Fran McDade committed Dec 31, 2024
1 parent db71e45 commit 0b9a3c9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/components/Table/features/RowPosition/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export function getRowModel<T extends RowData>(
const rowModel = getRowModel();
let i = 0;
rowModel.rows.forEach(({ getIsGrouped, id }) => {
const index = i; // Capture the current value of i for this iteration.
const isGroupedRow = getIsGrouped();
const index = isGroupedRow ? -1 : i; // Capture the current value of i for this iteration.
rowModel.rowsById[id].getRowPosition = (): number =>
calculateRowPosition(table, index);
if (getIsGrouped()) return; // Skip grouped rows.
if (isGroupedRow) return; // Iterate only for non-grouped rows.
i++;
});
return rowModel;
Expand Down Expand Up @@ -55,6 +56,7 @@ function calculateRowPosition<T extends RowData>(
table: Table<T>,
index: number
): number {
if (index < 0) return index; // Grouped rows have a position of -1.
const { getState } = table;
const {
pagination: { pageIndex, pageSize },
Expand Down

0 comments on commit 0b9a3c9

Please sign in to comment.