Skip to content

Commit d88f3dc

Browse files
committed
Add prop rowClassName
1 parent 358dc97 commit d88f3dc

File tree

6 files changed

+31
-2
lines changed

6 files changed

+31
-2
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Change Log
22

3+
## 3.5.0
4+
> Date: 2021-12-26
5+
### Added
6+
- New prop `rowClassName`
7+
38
## 3.4.0
49
> Date: 2021-12-23
510
### Added

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-datasheet-grid",
3-
"version": "3.4.0",
3+
"version": "3.5.0",
44
"description": "An Excel-like React component to create beautiful spreadsheets.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/components/DataSheetGrid.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export const DataSheetGrid = React.memo(
8585
onBlur = DEFAULT_EMPTY_CALLBACK,
8686
onActiveCellChange = DEFAULT_EMPTY_CALLBACK,
8787
onSelectionChange = DEFAULT_EMPTY_CALLBACK,
88+
rowClassName,
8889
}: DataSheetGridProps<T>,
8990
ref: React.ForwardedRef<DataSheetGridRef>
9091
): JSX.Element => {
@@ -1553,6 +1554,7 @@ export const DataSheetGrid = React.memo(
15531554
insertRowAfter,
15541555
stopEditing,
15551556
getContextMenuItems,
1557+
rowClassName,
15561558
})
15571559

15581560
const itemSize = useCallback(

src/components/Row.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ const RowComponent = React.memo(
2424
duplicateRows,
2525
stopEditing,
2626
getContextMenuItems,
27+
rowClassName,
2728
}: RowProps<any>) => {
2829
const firstRender = useFirstRender()
2930

@@ -50,7 +51,16 @@ const RowComponent = React.memo(
5051
}, [insertRowAfter, index])
5152

5253
return (
53-
<div className="dsg-row" style={style}>
54+
<div
55+
className={cx(
56+
'dsg-row',
57+
typeof rowClassName === 'string' ? rowClassName : null,
58+
typeof rowClassName === 'function'
59+
? rowClassName({ rowData: data, rowIndex: index })
60+
: null
61+
)}
62+
style={style}
63+
>
5464
{columns.map((column, i) => {
5565
const Component = column.component
5666

@@ -153,6 +163,7 @@ export const Row = <T extends any>({
153163
: undefined
154164
}
155165
getContextMenuItems={data.getContextMenuItems}
166+
rowClassName={data.rowClassName}
156167
/>
157168
)
158169
}

src/components/StaticDataSheetGrid.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export const StaticDataSheetGrid = React.forwardRef<
2020
onBlur,
2121
onActiveCellChange,
2222
onSelectionChange,
23+
rowClassName,
2324
...rest
2425
}: DataSheetGridProps<T>,
2526
ref: React.ForwardedRef<DataSheetGridRef>
@@ -36,6 +37,7 @@ export const StaticDataSheetGrid = React.forwardRef<
3637
onBlur,
3738
onActiveCellChange,
3839
onSelectionChange,
40+
rowClassName,
3941
})
4042

4143
return <DataSheetGrid {...staticProps} {...rest} ref={ref} />

src/types.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ export type ListItemData<T> = {
6464
insertRowAfter: (row: number, count?: number) => void
6565
stopEditing: (opts?: { nextRow?: boolean }) => void
6666
getContextMenuItems: () => ContextMenuItem[]
67+
rowClassName?:
68+
| string
69+
| ((opt: { rowData: T; rowIndex: number }) => string | undefined)
6770
}
6871

6972
export type HeaderContextType<T> = {
@@ -109,6 +112,9 @@ export type RowProps<T> = {
109112
insertRowAfter: (row: number, count?: number) => void
110113
stopEditing?: (opts?: { nextRow?: boolean }) => void
111114
getContextMenuItems: () => ContextMenuItem[]
115+
rowClassName?:
116+
| string
117+
| ((opt: { rowData: T; rowIndex: number }) => string | undefined)
112118
}
113119

114120
export type SimpleColumn<T, C> = Partial<
@@ -151,6 +157,9 @@ export type DataSheetGridProps<T> = {
151157
value?: T[]
152158
style?: React.CSSProperties
153159
className?: string
160+
rowClassName?:
161+
| string
162+
| ((opt: { rowData: T; rowIndex: number }) => string | undefined)
154163
onChange?: (value: T[], operations: Operation[]) => void
155164
columns?: Partial<Column<T, any>>[]
156165
gutterColumn?: SimpleColumn<T, any> | false

0 commit comments

Comments
 (0)