From 4be3010035d736e420701d244655b92d2b656b15 Mon Sep 17 00:00:00 2001 From: MichaelDimmitt Date: Wed, 29 Mar 2023 13:35:21 -0400 Subject: [PATCH 1/2] Allow rowClass to send row index, this will allow classes to be added positionally this change still supports adding classes by looking at the value with no breaking changes.. Now with positional support, if I want a css class applied to the last row in the table. Or the first row in the table. Currently you have to use a css pseudo class like .rdg-row:nth-child(14) to make the 14th row have a certain css behavior. An example of this has been added to the AllFeatures demo. --- src/DataGrid.tsx | 2 +- src/Row.tsx | 2 +- src/types.ts | 2 +- website/demos/AllFeatures.tsx | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/DataGrid.tsx b/src/DataGrid.tsx index 5217380625..73b627230b 100644 --- a/src/DataGrid.tsx +++ b/src/DataGrid.tsx @@ -179,7 +179,7 @@ export interface DataGridProps extends Sha * Miscellaneous */ renderers?: Maybe>; - rowClass?: Maybe<(row: R) => Maybe>; + rowClass?: Maybe<(row: R, rowIdx: number) => Maybe>; /** @default 'ltr' */ direction?: Maybe; 'data-testid'?: Maybe; diff --git a/src/Row.tsx b/src/Row.tsx index e2f9bd80d3..8aad64bd53 100644 --- a/src/Row.tsx +++ b/src/Row.tsx @@ -50,7 +50,7 @@ function Row( { [rowSelectedClassname]: selectedCellIdx === -1 }, - rowClass?.(row), + rowClass?.(row, rowIdx), className ); diff --git a/src/types.ts b/src/types.ts index 3e9049cb44..79780150e1 100644 --- a/src/types.ts +++ b/src/types.ts @@ -183,7 +183,7 @@ export interface RowRendererProps selectedCellDragHandle: ReactElement> | undefined; skipCellFocusRef: MutableRefObject; onRowChange: (column: CalculatedColumn, rowIdx: number, newRow: TRow) => void; - rowClass: Maybe<(row: TRow) => Maybe>; + rowClass: Maybe<(row: TRow, rowIdx: number) => Maybe>; setDraggedOverRowIdx: ((overRowIdx: number) => void) | undefined; selectCell: (position: Position, enableEditor?: Maybe) => void; } diff --git a/website/demos/AllFeatures.tsx b/website/demos/AllFeatures.tsx index 4b292deeeb..b889ac30e8 100644 --- a/website/demos/AllFeatures.tsx +++ b/website/demos/AllFeatures.tsx @@ -213,7 +213,7 @@ export default function AllFeatures({ direction }: Props) { selectedRows={selectedRows} onSelectedRowsChange={setSelectedRows} className="fill-grid" - rowClass={(row) => (row.id.includes('7') ? highlightClassname : undefined)} + rowClass={(row, index) => (row.id.includes('7') || index === 0 ? highlightClassname : undefined)} direction={direction} onCellClick={(args, event) => { if (args.column.key === 'title') { From b6f74b39a3d9b3c091da3388a0bf612c70087efb Mon Sep 17 00:00:00 2001 From: Nicolas Stepien Date: Thu, 13 Apr 2023 19:17:55 +0100 Subject: [PATCH 2/2] format --- website/demos/AllFeatures.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/website/demos/AllFeatures.tsx b/website/demos/AllFeatures.tsx index 7ac89116aa..26c4d4872c 100644 --- a/website/demos/AllFeatures.tsx +++ b/website/demos/AllFeatures.tsx @@ -213,7 +213,9 @@ export default function AllFeatures({ direction }: Props) { selectedRows={selectedRows} onSelectedRowsChange={setSelectedRows} className="fill-grid" - rowClass={(row, index) => (row.id.includes('7') || index === 0 ? highlightClassname : undefined)} + rowClass={(row, index) => + row.id.includes('7') || index === 0 ? highlightClassname : undefined + } direction={direction} onCellClick={(args, event) => { if (args.column.key === 'title') {