1
- import { ColDef } from 'ag-grid-community' ;
1
+ import { ColDef , ColSpanParams , themeQuartz } from 'ag-grid-community' ;
2
2
import { AgGridReact } from 'ag-grid-react' ;
3
- import { useEffect , useRef , useState } from 'react' ;
3
+ import { useEffect , useMemo , useRef , useState } from 'react' ;
4
4
5
5
import { Box } from '@/components' ;
6
6
import {
@@ -31,6 +31,16 @@ export const DatabaseGrid = ({
31
31
useState < Record < string , string | number | boolean > [ ] > ( ) ;
32
32
const [ colDefs , setColDefs ] = useState < ColDef [ ] > ( ) ;
33
33
34
+ const newRowColSpan = ( params : ColSpanParams < Record < string , string > > ) => {
35
+ const colsValues = params . data ?? { } ;
36
+ const isNewRow = Object . values ( colsValues ) [ 0 ] ?. includes ( 'new' ) ;
37
+ if ( isNewRow ) {
38
+ return Object . keys ( colsValues ) . length ;
39
+ }
40
+
41
+ return 1 ;
42
+ } ;
43
+
34
44
const addColumnColDef : ColDef = {
35
45
headerComponentParams : {
36
46
innerHeaderComponent : ( ) =>
@@ -62,11 +72,18 @@ export const DatabaseGrid = ({
62
72
rowData1 . push ( row ) ;
63
73
}
64
74
75
+ const addNewRow : Record < string , string > = { } ;
76
+ for ( const [ key ] of filteredEntries ) {
77
+ addNewRow [ key ] = '+ new row' ;
78
+ }
79
+ rowData1 . push ( addNewRow ) ;
80
+
65
81
setRowData ( rowData1 ) ;
66
82
67
83
const columnNames = Object . keys ( Object . fromEntries ( filteredEntries ) ) ;
68
84
const columns : ColDef [ ] = columnNames . map ( ( key ) => ( {
69
85
field : key ,
86
+ colSpan : newRowColSpan ,
70
87
} ) ) ;
71
88
72
89
setColDefs ( columns . concat ( addColumnColDef ) ) ;
@@ -78,8 +95,17 @@ export const DatabaseGrid = ({
78
95
filter : true ,
79
96
editable : true ,
80
97
unSortIcon : true ,
98
+ spanRows : true ,
81
99
} ;
82
100
101
+ const theme = useMemo ( ( ) => {
102
+ return themeQuartz . withParams ( {
103
+ pinnedRowBorder : {
104
+ width : 2 ,
105
+ } ,
106
+ } ) ;
107
+ } , [ ] ) ;
108
+
83
109
const addColumn = ( columnName : string ) => {
84
110
const newColDef : ColDef = {
85
111
field : columnName ,
@@ -115,6 +141,7 @@ export const DatabaseGrid = ({
115
141
defaultColDef = { defaultColDef }
116
142
domLayout = "autoHeight"
117
143
enableCellSpan = { true }
144
+ theme = { theme }
118
145
/>
119
146
</ Box >
120
147
) ;
0 commit comments