Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getGridRowStart util #3336

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
14 changes: 9 additions & 5 deletions src/DataGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,10 @@ function DataGrid<R, SR, K extends Key>(
);
}

function getGridRowStart(rowIdx: number) {
return headerAndTopSummaryRowsCount + 1 + rowIdx;
}

function selectCell(position: Position, enableEditor?: Maybe<boolean>): void {
if (!isCellWithinSelectionBounds(position)) return;
commitEditorChanges();
Expand Down Expand Up @@ -852,7 +856,7 @@ function DataGrid<R, SR, K extends Key>(

return (
<DragHandle
gridRowStart={headerAndTopSummaryRowsCount + rowIdx + 1}
gridRowStart={getGridRowStart(selectedPosition.rowIdx)}
rows={rows}
column={column}
columnWidth={columnWidth}
Expand Down Expand Up @@ -969,7 +973,7 @@ function DataGrid<R, SR, K extends Key>(
}

const row = rows[rowIdx];
const gridRowStart = headerAndTopSummaryRowsCount + rowIdx + 1;
const gridRowStart = getGridRowStart(rowIdx);
let key: K | number = rowIdx;
let isRowSelected = false;
if (typeof rowKeyGetter === 'function') {
Expand All @@ -980,7 +984,7 @@ function DataGrid<R, SR, K extends Key>(
rowElements.push(
renderRow(key, {
// aria-rowindex is 1 based
'aria-rowindex': headerAndTopSummaryRowsCount + rowIdx + 1,
'aria-rowindex': gridRowStart,
'aria-selected': isSelectable ? isRowSelected : undefined,
rowIdx,
row,
Expand Down Expand Up @@ -1137,8 +1141,8 @@ function DataGrid<R, SR, K extends Key>(
})}
{getViewportRows()}
{bottomSummaryRows?.map((row, rowIdx) => {
const gridRowStart = headerAndTopSummaryRowsCount + rows.length + rowIdx + 1;
const summaryRowIdx = rows.length + rowIdx;
const gridRowStart = getGridRowStart(summaryRowIdx);
const isSummaryRowSelected = selectedPosition.rowIdx === summaryRowIdx;
const top =
clientHeight > totalRowHeight
Expand Down Expand Up @@ -1190,7 +1194,7 @@ function DataGrid<R, SR, K extends Key>(
[rowSelectedWithFrozenCell]: isGroupRowFocused && lastFrozenColumnIndex !== -1
})}
style={{
gridRowStart: selectedPosition.rowIdx + headerAndTopSummaryRowsCount + 1
gridRowStart: getGridRowStart(selectedPosition.rowIdx)
}}
/>
)}
Expand Down