From 20f3001e466a717d81ba3200ad918197dea33454 Mon Sep 17 00:00:00 2001 From: Aman Mahajan Date: Wed, 6 Sep 2023 10:54:46 -0500 Subject: [PATCH] Add `getGridRowStart` util --- src/DataGrid.tsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index 1d7b31b609..7c3c9cc141 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -684,6 +684,10 @@ function DataGrid( ); } + function getGridRowStart(rowIdx: number) { + return headerAndTopSummaryRowsCount + 1 + rowIdx; + } + function selectCell(position: Position, enableEditor?: Maybe): void { if (!isCellWithinSelectionBounds(position)) return; commitEditorChanges(); @@ -810,7 +814,7 @@ function DataGrid( return ( ( } 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') { @@ -934,7 +938,7 @@ function DataGrid( rowElements.push( renderRow(key, { // aria-rowindex is 1 based - 'aria-rowindex': headerAndTopSummaryRowsCount + rowIdx + 1, + 'aria-rowindex': gridRowStart, 'aria-selected': isSelectable ? isRowSelected : undefined, rowIdx, row, @@ -1090,8 +1094,8 @@ function DataGrid( })} {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 @@ -1143,7 +1147,7 @@ function DataGrid( [rowSelectedWithFrozenCell]: isGroupRowFocused && lastFrozenColumnIndex !== -1 })} style={{ - gridRowStart: selectedPosition.rowIdx + headerAndTopSummaryRowsCount + 1 + gridRowStart: getGridRowStart(selectedPosition.rowIdx) }} /> )}